mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Update 0035.搜索插入位置.md
This commit is contained in:
@ -258,6 +258,37 @@ public int searchInsert(int[] nums, int target) {
|
||||
|
||||
|
||||
|
||||
### C#
|
||||
|
||||
```go
|
||||
public int SearchInsert(int[] nums, int target) {
|
||||
|
||||
var left = 0;
|
||||
var right = nums.Length - 1;
|
||||
|
||||
while (left <= right) {
|
||||
|
||||
var curr = (left + right) / 2;
|
||||
|
||||
if (nums[curr] == target)
|
||||
{
|
||||
return curr;
|
||||
}
|
||||
|
||||
if (target > nums[curr]) {
|
||||
left = curr + 1;
|
||||
}
|
||||
else {
|
||||
right = curr - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Golang
|
||||
|
||||
```go
|
||||
@ -500,3 +531,4 @@ int searchInsert(int* nums, int numsSize, int target){
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user