1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| // @Title: 检测大写字母 (Detect Capital)
// @Author: 15816537946@163.com
// @Date: 2021-11-13 13:43:28
// @Runtime: 0 ms
// @Memory: 2 MB
func detectCapitalUse(word string) bool {
n := len(word)
if n == 1 {
return true
}
isSameChar := isUpperChar(word[1])
for i :=1;i<len(word);i++ {
isUpper := isUpperChar(word[i])
if isSameChar != isUpper {
return false
}
isSameChar = isUpper
}
if isSameChar && !isUpperChar(word[0]) {
return false
}
return true
}
func isUpperChar(s byte) bool {
return s >='A' && s <='Z'
}
|