Leetcode Note: Go - Determine if String Halves Are Alike

Determine if String Halves Are Alike - LeetCode
https://leetcode.com/problems/determine-if-string-halves-are-alike/

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

回答

Go 0ms, 2.2MB 100%/100% so far - Determine if String Halves Are Alike - LeetCode
https://leetcode.com/problems/determine-if-string-halves-are-alike/solutions/989824/go-0ms-2-2mb-100-100-so-far/

func halvesAreAlike(s string) bool {
    half := len(s) / 2
    ctr := 0
    for i,r := range s {
        switch r {
            case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U':
                if i < half {
                    ctr++
                } else {
                    ctr--
                }
        }
    }
    return ctr == 0
}