这个题关键就是注意边界问题!!!!
错误一·:error: non-void function does not return a value in all control paths 返回值不全
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int i=0;
for(i=0;i<nums.size();i++)
{
if(nums[i]==target)
return i;
}
if(target<nums[0]) return 0;
for(i=0;i<nums.size()-1;i++)
{
if((nums[i]<target&&nums[i+1]>target))
return i+1;
}
if((i==nums.size()-1)&&(nums[nums.size()-1]!=target))
return i+1;
return -1;
}
};