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