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;
}
}
推荐阅读
- leetcode刷题|【leetcode每日刷题】35. Search Insert Position
- 数组(简单题)(搜索插入位置)
- 搜索插入位置(Search Insert Position)
- GO|马拉车算法
- GO|Golang刷题遇到的坑,sort排序相关
- Golang在OJ系统上的坑-输入相关
- leetcode题解-71. Simplify Path && 43. Multiply Strings
- 两数相加2(java)LeetCode第445题
- LeetCode【链表】2. 两数相加