Leetcode 35. Search Insert Position

来源:互联网 发布:飘零网络验证金盾版 编辑:程序博客网 时间:2024/06/05 11:01
public class Solution {    public int searchInsert(int[] nums, int target) {        int low = 0, high = nums.length-1, mid = 0;        while (low <= high) {            mid = (low+high) >> 1;            if (nums[mid] == target) return mid;            else if (nums[mid] > target) high = mid - 1;            else low = mid + 1;        }        return low;    }}

0 0