Byte by Byte

1812. Determine Color of a Chessboard Square.cpp 본문

개발 로그/알고리즘

1812. Determine Color of a Chessboard Square.cpp

CyberSoak 2021. 10. 7. 10:22

class Solution {
public:
    bool squareIsWhite(string coordinates) {
        string& s = coordinates;
        if((s[0]%2==0 &&s[1]%2==0) || s[0]%2==1&&s[1]%2==1) return false;
        return true;
    }
};


//better solution
class Solution {
public:
    bool squareIsWhite(string coordinates) {
        return coordinates[0]%2 != coordinates[1]%2;
    }
};