8000 update array.js · khemssharma/leetcode@8b24443 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 8b24443

Browse files
committed
update array.js
1 parent 262b1bb commit 8b24443

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

array.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,24 @@ var removeDuplicates = function (nums) {
1010
return k + 1;
1111
};
1212

13-
// maximum water area
13+
// search insert position
14+
var searchInsert = function (nums, target) {
15+
let left = 0,
16+
right = nums.length - 1;
17+
while (left <= right) {
18+
let mid = Math.floor((left + right) / 2);
19+
if (nums[mid] === target) {
20+
return mid;
21+
} else if (nums[mid] < target) {
22+
left = mid + 1;
23+
} else {
24+
right = mid - 1;
25+
}
26+
}
27+
return left;
28+
};
29+
30+
// container with most water
1431
var maxArea = function (height) {
1532
// two pointers
1633
let left = 0;

0 commit comments

Comments
0 (0)
0