赞
踩
题目:
题解:
- class Solution {
- public int searchInsert(int[] nums, int target) {
- int n = nums.length;
- int left = 0, right = n - 1, ans = n;
- while (left <= right) {
- int mid = ((right - left) >> 1) + left;
- if (target <= nums[mid]) {
- ans = mid;
- right = mid - 1;
- } else {
- left = mid + 1;
- }
- }
- return ans;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。