Skip to content

Commit 4c7c297

Browse files
Create 0035-search-insert-position.java
1 parent e4338a9 commit 4c7c297

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: java/0035-search-insert-position.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int searchInsert(int[] nums, int target) {
3+
//o(log n) and o(1)
4+
int low = 0, high = nums.length;
5+
while(low < high) {
6+
int mid = low + (high - low)/2;
7+
if(target > nums[mid])
8+
low = mid + 1;
9+
else
10+
high = mid;
11+
}
12+
return low;
13+
}
14+
}

0 commit comments

Comments
 (0)