mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加0035搜索插入位置 golang版本
This commit is contained in:
@ -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:
|
Python:
|
||||||
```python3
|
```python3
|
||||||
|
Reference in New Issue
Block a user