There was an error while loading. Please reload this page.
1 parent 20767e5 commit 4f1e942Copy full SHA for 4f1e942
2211-count-collisions-on-a-road/2211-count-collisions-on-a-road.cpp
@@ -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
22
+ ans += curr_right;
23
24
25
26
+ return ans;
27
28
+};
0 commit comments