1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// @Title: 寻找比目标字母大的最小字母 (Find Smallest Letter Greater Than Target)
// @Author: 15816537946@163.com
// @Date: 2019-11-18 11:45:47
// @Runtime: 0 ms
// @Memory: 2.8 MB
func nextGreatestLetter(letters []byte, target byte) byte {
	lo, hi := 0, len(letters)-1
	for lo < hi {
		mid := lo+(hi-lo)/2
		if letters[mid] <= target {
			lo = mid+1
		} else {
			hi = mid
		}
	}
	
	if lo >= len(letters) {
		return letters[0]
	}
	return letters[lo]
}