leetcode 第35题 搜索插入位置

class Solution { /* //暴力 public int searchInsert(int[] nums, int target) { for(int i=0; i=target) return i; } return nums.length; } */ //二分查找 public int searchInsert(int[] nums, int target) { return searchInsert(nums,target,0,nums.length); } public int searchInsert(int[] nums, int target,int start,int end) { while(startnums[start]) return start+1; else return start; } }

    推荐阅读