Created
November 28, 2019 02:35
-
-
Save kwojcicki/bd98c4b6da0d146d5b2acd986d157f81 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
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