Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int search(vector<int>& nums, int target) {
- int l = 0, r = nums.size() - 1;
- while (l <= r) {
- int mid = (l + r) / 2;
- if (nums[mid] == target) {
- return mid;
- }
- if (nums[mid] < target) {
- l = mid + 1;
- } else {
- r = mid - 1;
- }
- }
- return -1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement