Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
// BinarySearch BinarySearch
|
||||
func BinarySearch(s []string, t string, n int) (idx int) {
|
||||
idx = -1
|
||||
if n == 0 {
|
||||
return
|
||||
}
|
||||
start, end := 0, n-1
|
||||
for start <= end {
|
||||
mid := (start + end) >> 1
|
||||
if s[mid] < t {
|
||||
start = mid + 1
|
||||
} else if s[mid] > t {
|
||||
end = mid - 1
|
||||
} else {
|
||||
idx = mid
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var YesOrNo = map[bool]string{
|
||||
true: "是",
|
||||
false: "否",
|
||||
}
|
||||
Reference in New Issue
Block a user