luoheng
10/12/2019 - 11:53 AM

detectCapitalUse

func detectCapitalUse(word string) bool {
    if len(word) <= 1 {
        return true
    }
    var start byte = 'a'
    if word[0] >= 'A' && word[0] <= 'Z' {
        if word[1] >= 'A' && word[1] <= 'Z' {
            start = 'A'
        }
    }
    for i := 1; i < len(word); i++ {
        if word[i] < start || word[i] > start + 26 {
            return false
        }
    }
    return true
}