2038. Remove Colored Pieces if Both Neighbors are the Same Color
class Solution:
def winnerOfGame(self, colors: str) -> bool:
N = len(colors)
dic = defaultdict(int)
for i in range(N-2):
if colors[i] == colors[i+1] == colors[i+2]:
if colors[i] == 'A':
dic['A'] += 1
else:
dic['B'] += 1
return dic['A'] > dic['B']
O(N)
O(1)