添加0035搜索插入位置 golang版本

This commit is contained in:
perfumescent
2021-10-10 17:55:42 +08:00
parent b5dcc5583d
commit 92ba20009d

View File

@ -232,7 +232,24 @@ class Solution {
}
}
```
Golang:
```golang
// 第一种二分法
func searchInsert(nums []int, target int) int {
l, r := 0, len(nums) - 1
for l <= r{
m := l + (r - l)/2
if nums[m] == target{
return m
}else if nums[m] > target{
r = m - 1
}else{
l = m + 1
}
}
return r + 1
}
```
Python
```python3