Skip to content

Instantly share code, notes, and snippets.

@kwojcicki
Created December 1, 2019 23:00
Show Gist options
  • Save kwojcicki/404a4131085f8a63bb61fafdd3fa8518 to your computer and use it in GitHub Desktop.
Save kwojcicki/404a4131085f8a63bb61fafdd3fa8518 to your computer and use it in GitHub Desktop.
Pair findPairGivingSumUsingMap(int[] numbers, int k){
Set<Integer> seen = new HashSet<Integer>();
for(int i = 0; i < numbers.length; i++){
if(seen.contains(k - numbers[i])){
return new Pair(numbers[i], k - numbers[i]);
}
seen.add(numbers[i]);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment