We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3d5fad0 commit ee40352Copy full SHA for ee40352
2211. Count Collisions on a Road
@@ -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