Leetcode Nite: Go - Greatest English Letter in Upper and Lower Case

Greatest English Letter in Upper and Lower Case - LeetCode
https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case/

  • Go 言語で取り組んだメモ

回答

Simple Go / Golang - Greatest English Letter in Upper and Lower Case - LeetCode
https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case/solutions/2173493/simple-go-golang/

func greatestLetter(s string) string {
    occurrence := make([]bool, 'z'+1)
    diff := 'a' - 'A'
    
    for _, letter := range s {
        occurrence[letter] = true
    }
    
    for i := 'Z'; i >= 'A'; i-- {
        if occurrence[i] && occurrence[i+diff] {
            return string(i)
        }
    }
    
    return ""
}