Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- custom hook
- TypeScript
- manifest.json
- type
- codewars
- DB2
- useEffect
- TABLESPACE
- react
- IBM
- descendingOrder
- Debug
- JDBC
- codewar
- isSquare
- java api
- react hook
Archives
- Today
- Total
taesik
Write a function called sumZero which accepts a sorted array of integers. 본문
functions and trick/typescript_javascript
Write a function called sumZero which accepts a sorted array of integers.
taesikk 2022. 4. 29. 10:41The function should find the first pair where the sum is 0. Return an array that includes both values that sum to zero or undefined if a pair does not exist
function sumZero(arr) {
let left = 0;
let right = arr.length -1;
while(left < right) {
let sum = arr[left] + arr[right];
if(sum ===0) return [arr[left],arr[right]];
else if(sum>0) right--;
else left++;
}