关闭

LeetCode Search Insert Position

183人阅读 评论(0) 收藏 举报
分类:
class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int i;
        for(i=0;i<nums.size();i++){
            if(nums[i]>=target){
                break;
            }
        }
        return i;
    }
};

0
0
查看评论

Search Insert Position -- LeetCode

原题链接: http://oj.leetcode.com/problems/search-insert-position/  这道题比较简单,就是二分查找。思路就是每次取中间,如果等于目标即返回,否则根据大小关系切去一半。因此算法复杂度是O(logn),空间复杂度O(1)。代码如...
  • linhuanmars
  • linhuanmars
  • 2014-03-02 07:40
  • 12478

(Java)LeetCode-35. Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or...
  • u012848330
  • u012848330
  • 2016-08-07 21:46
  • 241

LeetCode35——Search Insert Position

LeetCode35——Search Insert Position 题意: 给定一个target,和有序序列,如果target在序列中,则返回其索引,否则给出当插入target且不改变序列性质时插入的位置(索引)。 思路依然是二分查找,找到就很简单直接返回,没找到,这个时候判断nums[lo...
  • zhangxiao93
  • zhangxiao93
  • 2015-10-15 22:01
  • 601

LeetCode解题报告--Search Insert Position

题目: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted...
  • github_27609763
  • github_27609763
  • 2015-12-04 16:58
  • 996

LeetCode 35 Search Insert Position(搜索并插入)

翻译给定一个已排序的数组和一个目标值,如果这个目标值能够在数组中找到则返回索引。如果不能,返回它应该被插入的位置的索引。你可以假设数组中没有重复项。以下是一些示例。原文Given a sorted array and a target value, return the index if the t...
  • NoMasp
  • NoMasp
  • 2015-11-28 21:16
  • 2305

LeetCode 35 Search Insert Position (C,C++,Java,Python)

Problem: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were ...
  • runningtortoises
  • runningtortoises
  • 2015-05-18 20:33
  • 1088

[LeetCode]35.Search Insert Position

【题目】 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inse...
  • SunnyYoona
  • SunnyYoona
  • 2015-01-24 15:07
  • 1406

【LeetCode-面试算法经典-Java实现】【035-Search Insert Position(搜索插入位置)】

【035-Search Insert Position(搜索插入位置)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a sorted array and a target value, return the index if the target is f...
  • DERRANTCM
  • DERRANTCM
  • 2015-07-27 07:18
  • 2395

35. Search Insert Position leetcode Python 2016 new season

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or...
  • hyperbolechi
  • hyperbolechi
  • 2016-01-20 11:01
  • 256

Python - Search Insert Position

【LeetCode with Python】 Search Insert Position  标签: LeetCodeLeetCode with PythonPython 2014-09-21 17:50 1027人阅读 评论(0) ...
  • screaming
  • screaming
  • 2016-01-16 19:52
  • 203
    个人资料
    • 访问:20982次
    • 积分:870
    • 等级:
    • 排名:千里之外
    • 原创:68篇
    • 转载:4篇
    • 译文:0篇
    • 评论:8条
    文章分类
    最新评论