Skip to content

Commit d4d53fd

Browse files
Create 0035-search-insert-position.go
1 parent 0cb22b5 commit d4d53fd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

go/0035-search-insert-position.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
func searchInsert(nums []int, target int) int {
2+
low, high := 0, len(nums)
3+
for low < high {
4+
mid := low + (high - low)/2
5+
if target > nums[mid] {
6+
low = mid + 1
7+
} else {
8+
high = mid
9+
}
10+
}
11+
return low
12+
}

0 commit comments

Comments
 (0)