Skip to content

Instantly share code, notes, and snippets.

@nishantkp
Created January 8, 2020 19:51
Show Gist options
  • Save nishantkp/fd0a2e08e5dc8e0668d7b0a0ae27eb5a to your computer and use it in GitHub Desktop.
Save nishantkp/fd0a2e08e5dc8e0668d7b0a0ae27eb5a to your computer and use it in GitHub Desktop.
List<Pair<Integer, Integer>> indices = new ArrayList<>();
// indeices will be list containing a Pair
// Pair first and second will be indecies of the numbers whose some will be "b"
int[] a = {1, 3, 4, 5, 2}; // your list
int b = 5; // number you want to compare
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (b == a[i] + a[j]) {
indices.add(Pair.create(i, j));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment