https://oj.leetcode.com/problems/search-insert-position/
http://fisherlei.blogspot.com/2013/01/leetcode-search-insert-position.html
public class Solution { public int searchInsert(int[] A, int target) { if (A == null) return -1; // invalid num if (A.length == 0) return 0; // empty array, no need to search. return search(A, target, 0, A.length - 1); } private int search(int[] A, int target, int low, int high) { if (low > high) return -1; if (low == high) { if (A[low] >= target) return low; else return low + 1; } int mid = (low + high) / 2; if (A[mid] == target) return mid; else if (A[mid] > target) return search(A, target, low, mid); else return search(A, target, mid + 1, high); // How to divide the array. } }