Leetcode Note: Go - Determine Color of a Chessboard Square

Determine Color of a Chessboard Square - LeetCode
https://leetcode.com/problems/determine-color-of-a-chessboard-square/description/

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

回答

Go that beats 100% - Determine Color of a Chessboard Square - LeetCode
https://leetcode.com/problems/determine-color-of-a-chessboard-square/solutions/2177397/go-that-beats-100/

func squareIsWhite(c string) bool {
    s := fmt.Sprintf("%c", c[0])
    r, _ := strconv.Atoi(fmt.Sprintf("%c", c[1]))
    
    if s == "a" || s == "c" || s == "e" || s == "g" {
        if r % 2 == 0 {
            return true
        }
    } else {
        if r % 2 == 1 {
            return true
        } 
    }
    
    return false
}