Skip to content

Commit 4f1e942

Browse files
committed
Time: 19 ms (51.01%), Space: 19.2 MB (84.64%) - LeetHub
1 parent 20767e5 commit 4f1e942

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
int countCollisions(string s) {
4+
int ans = 0;
5+
bool lblock = false;
6+
int curr_right = 0;
7+
int n = s.size();
8+
for(int i = 0; i < n; i++){
9+
if(s[i] == 'L'){
10+
if(curr_right){
11+
ans += 2;
12+
ans += curr_right - 1;
13+
curr_right = 0;
14+
lblock = true;
15+
}else if(lblock){
16+
ans += 1;
17+
}
18+
}else if(s[i] == 'R'){
19+
curr_right++;
20+
}else{
21+
lblock = true;
22+
ans += curr_right;
23+
curr_right = 0;
24+
}
25+
}
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
 (0)