60

来源:互联网 发布:codesys软件视频教程 编辑:程序博客网 时间:2024/04/28 19:10

4.20

public class Solution {    /**      * param A : an integer sorted array     * param target :  an integer to be inserted     * return : an integer     */    public int searchInsert(int[] A, int target) {        // write your code here        int length = A.length;        if(length == 0){            return 0;        }        if(A[0] > target){            return 0;        }        if(A[length -1 ] < target){            return length;        }        int i = 0;        for(i = 0;i < length;i++){            while(i < length-1 && A[i] < target ){                i++;            }            return i;        }        return i;            }}


0 0