[LeetCode] Search Insert Position
2014-06-18 21:25
513 查看
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.
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) { if(A[n-1] < target) return n; for(int i = 0;i<n;i++){ if(A[i]>target || A[i]==target) return i; }//end for } };
相关文章推荐
- leetcode之Search Insert Position
- [leetcode]Search Insert Position
- [leetcode]35. Search Insert Position(Java)
- LeetCode35. Search Insert Position
- 【LeetCode35】【Search Insert Position】二分法查找
- leetcode 35. Search Insert Position
- LeetCode35. Search Insert Position
- 【leetcode】Search Insert Position
- 【leetcode】Search Insert Position
- leetcode 35 -- Search Insert Position
- Leetcode::Search Insert Position
- 【leetcode】35. Search Insert Position
- leetcode: Search Insert Position
- Leetcode:search_insert_position
- leetcode 35. Search Insert Position
- LeetCode 35 Search Insert Position 二分法处理
- LeetCode Search Insert Position
- LeetCode --- 35. Search Insert Position
- LeetCode--search-insert-position
- leetcode_c++:Search insert position(035)