-
Notifications
You must be signed in to change notification settings - Fork 0
/
leet27.cpp
34 lines (34 loc) · 982 Bytes
/
leet27.cpp
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
29
30
31
32
33
34
class Solution {
public:
string pushDominoes(string s) {
int N = s.size(), right = -1;
for (int i = 0; i < N; ++i) {
if (s[i] == 'L') {
if (right == -1) {
for (int j = i - 1; j >= 0 && s[j] == '.'; --j) {
s[j] = 'L';
}
}
else {
for (int j = right + 1, k = i - 1; j < k; ++j, --k) {
s[j] = 'R';
s[k] = 'L';
}
right = -1;
}
}
else if (s[i] == 'R') {
if (right != -1) {
for (int j = right + 1; j < i; ++j)
s[j] = 'R';
}
right = i;
}
}
if (right != -1) {
for (int j = right + 1; j < N; ++j)
s[j] = 'R';
}
return s;
}
};