-
[LeetCode] 1812. Determine Color of a Chessboard SquareLeetCode 2021. 10. 22. 16:28728x90
https://leetcode.com/problems/determine-color-of-a-chessboard-square/
Determine Color of a Chessboard Square - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Determine Color of a Chessboard Square - Easy


체스판에서 주어진 부분이 흰칸이라면 True, 검은칸이라면 False를 리턴하는 문제다.
흰,검이 교차로 나타나므로 분명 규칙이 존재한다.
a1 = (0,1) => 검, a2 = (0,2) => 흰
b1 = (1,1) => 흰, b2 = (1,2) => 검
짝수 X 홀수 => 검
짝수 X 짝수 => 흰
홀수 X 홀수 => 흰
홀수 X 짝수 => 검
이므로,
!(a XOR b) 가 된다.
전체 풀이 코드
class Solution { public: bool squareIsWhite(string coordinates) { return !((coordinates[0]-'a')&1)^((coordinates[1]-'0')&1); } };'LeetCode' 카테고리의 다른 글
[LeetCode] 155. Min Stack (0) 2021.10.25 [LeetCode] 215. Kth Largest Element in an Array (0) 2021.10.22 [LeetCode] 6. ZigZag Conversion (0) 2021.10.22 [LeetCode] 451. Sort Characters By Frequency (0) 2021.10.22 [LeetCode] 1492. The kth Factor of n (0) 2021.10.21