[LeetCode]Search Insert Position
2014-03-14 11:13
417 查看
原题链接:http://oj.leetcode.com/problems/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 order.
You may assume no duplicates in the array.
Here are few examples.
题解:
水题。
View Code
题意描述:
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 order.
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
题解:
水题。
class Solution { public: int searchInsert(int A[], int n, int target) { for(int i=0; i<n; i++){ if(target <= A[i]) return i; } return n; } };
View Code
相关文章推荐
- LeetCode-Search Insert Position
- LeetCode 35. Search Insert Position
- LeetCode之Search Insert Position
- LeetCode之路——LeetCode_35_ Search Insert Position
- LeetCode题解:Search Insert Position
- [LeetCode]035-Search Insert Position
- 【LeetCode】Search Insert Position搜索插入位置[数组、二分法] - Medium
- Leetcode-Search Insert Position-Python
- LeetCode 35. Search Insert Position
- leetcode刷题记录-35. Search Insert Position
- [leetcode] 【查找】 35. Search Insert Position
- leetcode 日经贴,Cpp code -Search Insert Position
- Leetcode_search-insert-position
- LeetCode -- Search Insert Position
- leetcode---search-insert-position---查找
- 【Leetcode】Lee.35. Search Insert Position
- Leetcode-35. Search Insert Position
- LeetCode:Search Insert Position
- 个人记录-LeetCode 35. Search Insert Position
- [leetcode]Search Insert Position @ Python