Skip to content

Commit 30a2236

Browse files
committed
add step4 for Search Insert Position
1 parent 51d351e commit 30a2236

File tree

1 file changed

+15
-0
lines changed
  • pullrequests/search_insert_position

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//lint:file-ignore U1000 Ignore all unused code
2+
package searchinsertposition
3+
4+
func searchInsert(nums []int, target int) int {
5+
left, right := 0, len(nums)
6+
for left < right {
7+
mid := left + (right-left)/2
8+
if nums[mid] < target {
9+
left = mid + 1
10+
} else {
11+
right = mid
12+
}
13+
}
14+
return left
15+
}

0 commit comments

Comments
 (0)