[HAI] week3 two sum withou hashsum

https://leetcode.com/problems/two-sum-ii-input-array-is-sorted
This commit is contained in:
2024-12-06 00:00:04 +03:00
parent 8dcb175459
commit a54b5b8996
4 changed files with 150 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
export function twoSum(numbers: number[], target: number): number[] {
let L = 0;
let R = numbers.length - 1;
while (L <= R) {
const curSum = numbers[L] + numbers[R];
if (curSum === target) return [L + 1, R + 1];
curSum > target ? R-- : L++;
}
return [-1, -1];
};