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

[leetcode-35-Search Insert Position]

时间:2017-06-04 18:24:25      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:tor   amp   array   tco   return   pos   nbsp   cat   int   

You may assume no duplicates in the array.
Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0

int searchInsert(vector<int>& nums, int target)
     {
         int len = nums.size();
         if (len == 0 || nums[0]>=target)return 0;
         for (int i = 1; i < len;i++)
         {
             if (nums[i]==target) return i;
             if (nums[i]>target && target>nums[i - 1])return i;
         }
         return len;
     }

 

[leetcode-35-Search Insert Position]

标签:tor   amp   array   tco   return   pos   nbsp   cat   int   

原文地址:http://www.cnblogs.com/hellowooorld/p/6940867.html

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