MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / pushDominoes

Method pushDominoes

python/0838-push-dominoes.py:2–23  ·  view source on GitHub ↗
(self, dominoes: str)

Source from the content-addressed store, hash-verified

1class Solution:
2 def pushDominoes(self, dominoes: str) -> str:
3 dom = list(dominoes)
4 q = collections.deque()
5 for i, d in enumerate(dom):
6 if d != '.':
7 q.append((i, d))
8
9 while q:
10 i, d = q.popleft()
11
12 if d == 'L' and i > 0 and dom[i - 1] == '.':
13 q.append((i - 1, 'L'))
14 dom[i - 1] = 'L'
15 elif d == 'R':
16 if i + 1 < len(dom) and dom[i + 1] == '.':
17 if i + 2 < len(dom) and dom[i + 2] == 'L':
18 q.popleft()
19 else:
20 q.append((i + 1, 'R'))
21 dom[i + 1] = 'R'
22
23 return ''.join(dom)

Callers

nothing calls this directly

Calls 2

listFunction · 0.85
popleftMethod · 0.80

Tested by

no test coverage detected