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

Let's Develop Together!
Download Telegram
image_2021-10-29_14-53-36.png
39.9 KB
#N704. Binary Search
problem link=>https://leetcode.com/problems/binary-search/

#solution
class Solution {
public int search(int[] nums, int target) {
int left=0, right=nums.length-1, mid;
while(left<=right){
mid=(left+right)/2;
if(nums[mid]<target){
left=mid+1;
}
if(nums[mid]>target){
right=mid-1;
}

if(nums[mid]==target){
return mid;
}
}

return -1;
}
}

‼️Implementation of Bineary Search to the problems