520. 检测大写字母

检测大写字母

解法一: 模拟

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func detectCapitalUse(word string) bool {
n := len(word)
// true:大写;false:小写
fisrtUpper := word[0] <= 'Z'
pre := false
for i := 1; i < n; i++ {
if i == 1 {
pre = word[i] <= 'Z'
continue
}
if pre != (word[i] <= 'Z') {
return false
}
}
return fisrtUpper || !fisrtUpper && !pre
}
作者

wuhunyu

发布于

2024-06-23

更新于

2025-01-15

许可协议