Untitled
class Solution { public: int searchInsert(vector<int>& nums, int t) { int s=0,e=nums.size()-1; int mid=0; while(s<=e){ mid =s+(e-s)/2; if(nums[mid]<t) s=mid+1; else if(nums[mid]>t) e=mid-1; else if(nums[mid]==t) return mid; } return s; } };
class Solution { public: int searchInsert(vector<int>& nums, int t) { int s=0,e=nums.size()-1; int mid=0; while(s<=e){ mid =s+(e-s)/2; if(nums[mid]<t) s=mid+1; else if(nums[mid]>t) e=mid-1; else if(nums[mid]==t) return mid; } return s; } };