码迷,mamicode.com
首页 > 其他好文 > 详细

Search Insert Position

时间:2017-03-30 22:30:55      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:log   code   思路   search   div   solution   pos   get   arch   

思路:注意特殊情况的处理,如[1]:0,[1]:2

class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int index = -1, i = 0;
        for(; i<nums.size(); ++i)
        {
            if(nums[i] == target)
                return i;
                
            if(nums[i] < target)
                index = i;
        }
        
        return index+1;
    }
};

 

Search Insert Position

标签:log   code   思路   search   div   solution   pos   get   arch   

原文地址:http://www.cnblogs.com/chengyuz/p/6648910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!