Skip to content

Instantly share code, notes, and snippets.

@misterpoloy
Created May 21, 2021 21:14
Show Gist options
  • Save misterpoloy/39493eadf62d9f991c8f55c3cd273f4e to your computer and use it in GitHub Desktop.
Save misterpoloy/39493eadf62d9f991c8f55c3cd273f4e to your computer and use it in GitHub Desktop.
Two pointer patter sumzero
Function sumZero(arr) {
let left = 0;
let right = aro.length -1;
while (left < right) {
let sum = arr[left] + arr[right];
if (sum == 0) {
return [arr[left]], arr[right]
} else {
right—;
} else {
left++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment