-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-269.cpp
35 lines (35 loc) · 1.04 KB
/
Day-269.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
35
class Solution {
public:
string pushDominoes(string dominoes) {
const int &n = dominoes.size();
vector<int>v(dominoes.size() , INT_MAX);
int counter{-1};
string temp = dominoes;
for (int i=0; i<n; ++i) { // left
// L..R.L.
if (dominoes[i] == 'R') {
counter = 0;
} else if(dominoes[i]=='L') {
counter = -1;
} else if (dominoes[i]=='.' && counter != -1) {
temp[i] = 'R';
v[i] = counter++;
}
}
for (int i=n-1; i>=0; --i) {
if (dominoes[i] == 'L') {
counter = 0;
} else if (dominoes[i] == 'R') {
counter = -1;
} else if (dominoes[i] == '.' && counter != -1) {
if (v[i] > counter) {
temp[i] = 'L';
counter++;
} else if(v[i]==counter){
temp[i] = '.';
}
}
}
return temp;
}
};