Skip to content

Commit 9428ccd

Browse files
committed
Time: 0 ms (100%), Space: 46 MB (22.77%) - LeetHub
1 parent 26efa68 commit 9428ccd

File tree

1 file changed

+19
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)