Skip to content

Commit 48104a6

Browse files
authored
Create 2211. Count Collisions on a Road (#949)
2 parents 3d5fad0 + ee40352 commit 48104a6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

2211. Count Collisions on a Road

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int countCollisions(string directions) {
4+
int n = directions.size();
5+
int left = 0, right = n - 1;
6+
int cnt = 0;
7+
while (left < n && directions[left] == 'L'){
8+
left++;
9+
}
10+
while (right >= 0 && directions[right] == 'R'){
11+
right--;
12+
}
13+
if (left > right){
14+
return 0;
15+
}
16+
for (int i = left; i <= right; i++){
17+
if (directions[i] != 'S'){
18+
cnt++;
19+
}
20+
}
21+
return cnt;
22+
}
23+
};

0 commit comments

Comments
 (0)