Skip to content

Commit 6b95e72

Browse files
authored
Create remove-colored-pieces-if-both-neighbors-are-the-same-color.py
1 parent daf4a3e commit 6b95e72

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def winnerOfGame(self, colors):
6+
"""
7+
:type colors: str
8+
:rtype: bool
9+
"""
10+
cnt1 = cnt2 = 0
11+
for i in xrange(1, len(colors)-1):
12+
if not (colors[i-1] == colors[i] == colors[i+1]):
13+
continue
14+
if colors[i] == 'A':
15+
cnt1 += 1
16+
else:
17+
cnt2 += 1
18+
return cnt1 > cnt2

0 commit comments

Comments
 (0)