Skip to content

Commit 85a575f

Browse files
Added Leetcode Problem-35
1 parent e286531 commit 85a575f

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int searchInsert(int[] nums, int target) {
3+
int low = 0;
4+
int high = nums.length - 1;
5+
6+
while(low <= high) {
7+
int mid = low + (high - low) / 2;
8+
9+
if(nums[mid] == target){
10+
return mid;
11+
} else if (nums[mid] > target) {
12+
high = mid - 1;
13+
14+
} else {
15+
low = mid + 1;
16+
}
17+
18+
}
19+
20+
return low;
21+
}
22+
}

0 commit comments

Comments
 (0)