Skip to content

Commit 6f616b5

Browse files
committed
https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/
1 parent cb386f8 commit 6f616b5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ https://leetcode.cn/problems/NYBBNL/
618618

619619
https://leetcode.cn/problems/increasing-order-search-tree/
620620

621+
https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/
622+
621623
#### 安装教程
622624

623625
1. 安装`deno`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default function twoSum(numbers: number[], target: number): number[] {
2+
let left = 0;
3+
let right = numbers.length - 1;
4+
5+
while (right - left >= 1) {
6+
const sum = numbers[left] + numbers[right];
7+
8+
if (sum === target) {
9+
return [left + 1, right + 1];
10+
} else if (sum < target) {
11+
left++;
12+
} else {
13+
right--;
14+
}
15+
}
16+
return [-1, -1];
17+
}

0 commit comments

Comments
 (0)