mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Merge pull request #834 from perfumescent/master
Update 0035 添加0035搜索插入位置 golang版本 & 将0034的页面链接添加至0704的相关题目推荐
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:
|
||||
```python3
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
## 相关题目推荐
|
||||
|
||||
* [35.搜索插入位置](https://programmercarl.com/0035.搜索插入位置.html)
|
||||
* 34.在排序数组中查找元素的第一个和最后一个位置
|
||||
* [34.在排序数组中查找元素的第一个和最后一个位置](https://programmercarl.com/0034.%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%92%8C%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E4%BD%8D%E7%BD%AE.html)
|
||||
* 69.x 的平方根
|
||||
* 367.有效的完全平方数
|
||||
|
||||
|
Reference in New Issue
Block a user