Skip to content

Instantly share code, notes, and snippets.

@hkasera
Created June 1, 2020 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkasera/7c521757c78cf364bffedf3e94a5a0aa to your computer and use it in GitHub Desktop.
Save hkasera/7c521757c78cf364bffedf3e94a5a0aa to your computer and use it in GitHub Desktop.
private boolean sumsToTarget(int[] arr, int k) {
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++) {
int siblingIndex = Arrays.binarySearch(arr, k - A[i]);
if (siblingIndex >= 0) {
// Found it!
if (siblingIndex != i || (i > 0 && arr[i-1] == arr[i]) || (i < arr.length - 1 && arr[i+1] == arr[i]))
{ return true; }
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment