-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path0838.cpp
More file actions
31 lines (27 loc) · 829 Bytes
/
Copy path0838.cpp
File metadata and controls
31 lines (27 loc) · 829 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
29
30
31
class Solution {
public:
string pushDominoes(const string &dominoes) const {
static int forces[100001];
const int n = size(dominoes);
string res(n, '.');
for (int i = 0, force = 0; i < n; i++) {
if (dominoes[i] == 'R')
force = n;
else if (dominoes[i] == 'L')
force = 0;
else
force = max(force - 1, 0);
forces[i] = force;
}
for (int i = n - 1, force = 0; i >= 0; i--) {
if (dominoes[i] == 'L')
force = n;
else if (dominoes[i] == 'R')
force = 0;
else
force = max(force - 1, 0);
if (forces[i] != force) res[i] = forces[i] > force ? 'R' : 'L';
}
return res;
}
};