1
class Solution {
2
public:
3
string pushDominoes(string dominoes) {
4
#define SET(ch, arr) \
5
if (dominoes[i] == ch) { \
6
count = 1; \
7
prev = ch; \
8
} else if (dominoes[i] != '.') \
9
prev = dominoes[i]; \
10
if (prev == ch && dominoes[i] == '.') arr[i] = count++;
11

12
string res = "";
13
char prev;
14
int n = dominoes.size(), count = 1;
15

16
vector<int> left(n, 0), right(n, 0);
17
for (int i = 0; i < n; i++) {
18
SET('R', right);
19
}
20

21
prev = '.';
22
for (int i = n - 1; i >= 0; i--) {
23
SET('L', left);
24
}
25

26
for (int i = 0; i < n; i++) {
27
if (!left[i] && !right[i])
28
res += dominoes[i];
29
else if (!left[i])
30
res += 'R';
31
else if (!right[i])
32
res += 'L';
33
else if (left[i] == right[i])
34
res += '.';
35
else if (left[i] < right[i])
36
res += 'L';
37
else
38
res += 'R';
39
}
40

41
return res;
42
}
43
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0