Skip to content

Instantly share code, notes, and snippets.

@kwojcicki
Created December 1, 2019 22:58
Show Gist options
  • Save kwojcicki/11e425c3d5895685fb134a989843832c to your computer and use it in GitHub Desktop.
Save kwojcicki/11e425c3d5895685fb134a989843832c to your computer and use it in GitHub Desktop.
Pair findPairUsingSorted(int[] numbers, int k){
int first = 0;
int last = numbers.length - 1;
while(true){
if(numbers[first] + numbers[last] < k){
first++;
} else if(numbers[first] + numbers[last] > k){
last--;
} else {
return new Pair(numbers[first], numbers[last]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment