Leetcode in Java && Oracle
420 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-27_01-37-20.png
32.3 KB
#N35. Search Insert Position
problem link

#solution
class Solution {
public int searchInsert(int[] nums, int target) {
int start=0, end=nums.length-1, mid;

while(start<=end){
mid=(start+end)/2;
if(nums[mid]==target) return mid;
else if(nums[mid]<target) start=mid+1;
else if(nums[mid]>target) end=mid-1;
}

return start;
}
}