| 1 | //时间复杂度:O(lon(n)) |
| 2 | //空间复杂度:O(1) |
| 3 | class Solution2 { |
| 4 | public int searchInsert(int[] nums, int target) { |
| 5 | if (target>nums[nums.length-1]) { |
| 6 | return nums.length; |
| 7 | } |
| 8 | int left=0; |
| 9 | int right=nums.length-1; |
| 10 | while (left < right) { |
| 11 | int mid = (left + right) / 2; |
| 12 | if (nums[mid] < target) { |
| 13 | left = mid + 1; |
| 14 | } else { |
| 15 | right = mid; |
| 16 | } |
| 17 | } |
| 18 | return left; |
| 19 | |
| 20 | } |
| 21 | } |
nothing calls this directly
no outgoing calls
no test coverage detected