unicode
包里面有 IsUpper
方法可以用来判断是否是大写字母
func detectCapitalUse(word string) bool {
if len(word) <= 1 {
return true
}
firstUpper := unicode.IsUpper(rune(word[0]))
secondUpper := unicode.IsUpper(rune(word[1]))
if !firstUpper && secondUpper {
return false
}
for k, s := range word {
if k <= 1 {
continue
}
if secondUpper != unicode.IsUpper(s) {
return false
}
}
return true
}
标签:力扣,word,检测,大写字母,520,leetcode
From: https://www.cnblogs.com/wudanyang/p/17003491.html