-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet2025.cpp
More file actions
32 lines (29 loc) · 816 Bytes
/
leet2025.cpp
File metadata and controls
32 lines (29 loc) · 816 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
32
class Solution {
public:
string pushDominoes(string s) {
s = 'L' + s + 'R';
string res;
int prev = 0;
for (int curr = 1; curr < s.size(); ++curr) {
if (s[curr] == '.') {
continue;
}
int span = curr - prev - 1;
if (prev > 0)
res += s[prev];
if (s[prev] == s[curr]) {
res += string(span, s[prev]);
}
else if (s[prev] == 'L' && s[curr] == 'R') {
res += string(span, '.');
}
else {
res += string(span / 2, 'R')
+ string(span % 2, '.')
+ string(span / 2, 'L');
}
prev = curr;
}
return res;
}
};