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