Skip to content

Commit ddc6ee3

Browse files
authored
Create check-if-two-chessboard-squares-have-the-same-color.py
1 parent 699f4bd commit ddc6ee3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
# math, parity
5+
class Solution(object):
6+
def checkTwoChessboards(self, coordinate1, coordinate2):
7+
"""
8+
:type coordinate1: str
9+
:type coordinate2: str
10+
:rtype: bool
11+
"""
12+
def parity(a):
13+
return reduce(lambda accu, x: (accu+x)%2, (ord(x) for x in a), 0)
14+
15+
return parity(coordinate1) == parity(coordinate2)

0 commit comments

Comments
 (0)