search insert position
1 class Solution { 2 public: 3 int searchInsert(int A[], int n, int target) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int lt = 0, rt = n-1; 7 while(lt <= rt ) 8 { 9 int mid = (lt + rt )/2; 10 if( A[mid] == target ) 11 return mid; 12 else if( A[mid] > target ) 13 rt = mid - 1; 14 else 15 lt = mid + 1; 16 } 17 return lt; 18 } 19 };
posted on 2013-07-03 17:31 jumping_grass 阅读(151) 评论(0) 收藏 举报
浙公网安备 33010602011771号