blob: 64fe023fbc3501c0d5c4e51fe6ad6790bf6f9cf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 2038. Remove Colored Pieces if Both Neighbors are the Same Color
from collections import Counter
class Solution(object):
def winnerOfGame(self, colours):
c = collections.Counter()
for x, t in groupby(colours):
c[x] += max(len(list(t)) - 2, 0)
if c["A"] > c["B"]:
return True
return False
if __name__ == "__main__":
obj = Solution()
print(obj.winnerOfGame("AAABABB")) # expect: 1
print(obj.winnerOfGame("AA")) # expect: 0
print(obj.winnerOfGame("ABBBBBBBAAA")) # expect: 0
|