-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path163.py
More file actions
28 lines (23 loc) · 683 Bytes
/
163.py
File metadata and controls
28 lines (23 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution:
def pushDominoes(self, dominoes: str) -> str:
n = len(dominoes)
force = [0] * n
f = 0
for i in range(n):
if dominoes[i] == "R":
f = n
elif dominoes[i] == "L":
f = 0
else:
f = max(f - 1, 0)
force[i] += f
f = 0
for i in range(n - 1, -1, -1):
if dominoes[i] == "R":
f = 0
elif dominoes[i] == "L":
f = n
else:
f = max(f - 1, 0)
force[i] -= f
return "".join("." if f == 0 else "R" if f > 0 else "L" for f in force)