Skip to content

Commit 3620d1b

Browse files
committed
Add Solution2.java for 0035.Search Insert Position
1 parent bbe96a3 commit 3620d1b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
3+
public int searchInsert(int[] nums, int target) {
4+
int len = nums.length;
5+
if (len == 0) return 0;
6+
7+
int left = 0, right = len;
8+
9+
while (left < right) {
10+
int mid = left + (right - left) / 2;
11+
if (nums[mid] < target) {
12+
left = mid + 1;
13+
} else {
14+
right = mid;
15+
}
16+
}
17+
return left;
18+
}
19+
}

0 commit comments

Comments
 (0)