Created
May 21, 2021 21:14
-
-
Save misterpoloy/39493eadf62d9f991c8f55c3cd273f4e to your computer and use it in GitHub Desktop.
Two pointer patter sumzero
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
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