mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 08:27:30 +08:00
规范格式
This commit is contained in:
16
leetcode/0704.Binary-Search/704. Binary Search.go
Normal file
16
leetcode/0704.Binary-Search/704. Binary Search.go
Normal file
@ -0,0 +1,16 @@
|
||||
package leetcode
|
||||
|
||||
func search704(nums []int, target int) int {
|
||||
low, high := 0, len(nums)-1
|
||||
for low <= high {
|
||||
mid := low + (high-low)>>1
|
||||
if nums[mid] == target {
|
||||
return mid
|
||||
} else if nums[mid] > target {
|
||||
high = mid - 1
|
||||
} else {
|
||||
low = mid + 1
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
Reference in New Issue
Block a user