Skip to content

Commit a9ba6b6

Browse files
authored
Update Solution.ts
1 parent e3510c9 commit a9ba6b6

File tree

1 file changed

+7
-7
lines changed
  • solution/0000-0099/0035.Search Insert Position

1 file changed

+7
-7
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function searchInsert(nums: number[], target: number): number {
2-
let [l, r] = [0, nums.length - 1];
3-
4-
while (l <= r) {
2+
let [l, r] = [0, nums.length];
3+
while (l < r) {
54
const mid = (l + r) >> 1;
6-
if (nums[mid] === target) return mid;
7-
if (nums[mid] < target) l = mid + 1;
8-
else r = mid - 1;
5+
if (nums[mid] >= target) {
6+
r = mid;
7+
} else {
8+
l = mid + 1;
9+
}
910
}
10-
1111
return l;
1212
}

0 commit comments

Comments
 (0)