35. Search Insert Position
2017-05-22 11:18
316 查看
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Here are few examples.
public class Solution {
public int searchInsert(int[] nums, int target) {
int i=0;
while(i<nums.length && target > nums[i]){
i++;
}
return i;
}
}
You may assume no duplicates in the array.
Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0
public class Solution {
public int searchInsert(int[] nums, int target) {
int i=0;
while(i<nums.length && target > nums[i]){
i++;
}
return i;
}
}
相关文章推荐
- LeetCode 35 -Search Insert Position ( JAVA )
- LeetCode 35: Search Insert Position
- LeetCode-35:Search Insert Position(寻找或插入位置)
- [leetcode] 35. Search Insert Position
- [LeetCode-35] Search Insert Position(二分法)
- LeetCode-35-Search Insert Position(C语言实现)
- 35. Search Insert Position
- [LeetCode35]Search Insert Position
- Leetcode_35_Search Insert Position
- 35. Search Insert Position
- LeetCode 35 Search Insert Position(搜索并插入)
- 35. Search Insert Position
- leetcode 35: Search Insert Position
- [LeetCode] 35. Search Insert Position
- 2018.04.02 leeycode 打卡 #35 . Search Insert Position
- 35. Search Insert Position
- Leetcode 35 - Search Insert Position
- Leetcode---35. Search Insert Position
- LeetCode(35) Search Insert Position
- [LeetCode] 35 - Search Insert Position