diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md index 593e3fe5..914c2679 100644 --- a/problems/0035.搜索插入位置.md +++ b/problems/0035.搜索插入位置.md @@ -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 diff --git a/problems/0704.二分查找.md b/problems/0704.二分查找.md index e1900276..1cdc5896 100644 --- a/problems/0704.二分查找.md +++ b/problems/0704.二分查找.md @@ -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.有效的完全平方数