Created
January 8, 2020 19:51
-
-
Save nishantkp/fd0a2e08e5dc8e0668d7b0a0ae27eb5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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