演算法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.
[1,3,5,6], 5 -> 2 [1,3,5,6], 2 -> 1 [1,3,5,6], 7 -> 4 [1,3,5,6], 0 -> 0
public class Solution { public int searchInsert(int[] A, int target) { if(A==null) return 0; if(target <= A[0]) return 0; for(int i=0; i
A[i] && target <= A[i+1]){ return i+1; } } return A.length; } }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29012686/viewspace-1153251/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Search Insert Position
- Leetcode Search Insert PositionLeetCode
- Leetcode 35 Search Insert PositionLeetCode
- Leetcode-Search Insert PositionLeetCode
- Search Insert Position leetcode javaLeetCodeJava
- LeetCode 35. Search Insert PositionLeetCode
- [LeetCode] Search Insert Position 搜尋插入位置LeetCode
- Search Insert Position 查詢給定元素在陣列中的位置,若沒有則返回應該在的位置陣列
- ES(Elastic Search)update操作設定無 docment時進行insertAST
- Algorithm-search 查詢演算法 pythonGo演算法Python
- position
- dijkstra and A* search 演算法心得及JS實現演算法JS
- CSS position:sticky與position:fixed 區別CSS
- Position定位
- css positionCSS
- jQuery position()jQuery
- Oracle中的insert/insert all/insert firstOracle
- Elasticsearch中URI Search和RequestBody Search分析Elasticsearch
- 解析position: sticky;
- position和float
- position和BFC
- CSS之positionCSS
- jQuery position()方法jQuery
- JavaScript search()JavaScript
- PDF Search mac如何使用?PDF Search使用教程Mac
- list-style-position
- CSS background-positionCSS
- check_document_position
- Position定位詳解
- css的position:absoluteCSS
- CSS的定位:positionCSS
- sqlloader指定positionSQL
- 頭寸(position)(zt)
- CSS之定位PositionCSS
- LintCode-Search Range in Binary Search Tree
- Elasticsearch Search APIElasticsearchAPI
- Oracle 的 INSERT ALL和INSERT FIRSTOracle
- insert /*+ append */ into 與insert into 的區別APP