Skip to content

Commit dde993a

Browse files
authored
Create 704. Binary Search 1 apr (#135)
2 parents 55672a4 + edc4b56 commit dde993a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

704. Binary Search 1 apr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int search(vector<int>& nums, int target) {
4+
int s=0,e=nums.size()-1;
5+
while(s<=e){
6+
int m=(s+e)/2;
7+
if(nums[m]==target)return m;
8+
else if(nums[m]>target)e=m-1;
9+
else s=m+1;
10+
}
11+
return -1;
12+
}
13+
14+
};

0 commit comments

Comments
 (0)