Skip to content

Commit

Permalink
Create 704-Binary-Search.java
Browse files Browse the repository at this point in the history
  • Loading branch information
acmoroca authored Apr 3, 2022
1 parent 0705245 commit b80f151
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 704-Binary-Search.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int search(int[] nums, int target) {

int i = 0;
int j = nums.length-1;

while(i<=j){
int mid = (i+j)/2;

if(nums[mid] == target) return mid;
else if(nums[mid]<target) i = mid+1;
else j = mid-1;
}
return -1;
}
}

0 comments on commit b80f151

Please sign in to comment.