35. 搜索插入位置

题目链接:https://leetcode-cn.com/problems/search-insert-position/

执行用时:28 ms, 在所有 Swift 提交中击败了84.96%的用户
内存消耗:13.4 MB, 在所有 Swift 提交中击败了98.89%的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
func searchInsert(_ nums: [Int], _ target: Int) -> Int {
var left = 0, right = nums.count - 1
while left <= right {
var mid = left + (right - left)/2
if nums[mid] < target {
left = mid + 1
}else{
right = mid - 1
}
}
return left
}
}

35. 搜索插入位置
https://pisces34.github.io/2021/08/18/leetcode/35/
发布于
2021年8月18日
许可协议