LeetCode 035 Search Insert Position

来源:互联网 发布:js json转换对象数组 编辑:程序博客网 时间:2024/06/07 18:49
题目


找到数组中的插入点。


题目


public class Solution {    public int searchInsert(int[] A, int target) {        if(A.length==0){            return 0;        }        int start =0;        int end = A.length-1;        while(start<=end){            int mid = start +(end-start)/2;            if(A[mid]<target){                start=mid+1;                continue;            }            if(A[mid]>=target){                end = mid-1;                continue;            }        }        return start;    }}

此类题目一定二分法来做,不需要特别说明

0 0