数组中寻找插入位置算法

public static void main(String[] args) { int[] nums = {1}; System.out.println(searchInsert(nums ,1)); } public static int searchInsert(int[] nums, int target) { int flag = 0; for(int i=0; inums[i]; i++){ if(target == nums[i]){ if(i==0){ flag = 0; }else{ flag = i; } }else if(target > nums[i]){ ++ flag; }else{ flag = i; } }return flag; }


    推荐阅读