All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 14, 2024
Last updated : July 14, 2024
Related Topics : String, Stack, Simulation
Acceptance Rate : 43.96 %
class Solution:
def countCollisions(self, directions: str) -> int:
cols = 0
lCounter = 0
last = 'R'
for c in reversed(directions) :
if c == 'L' :
lCounter += 1
last = c
elif c == 'S' :
cols += lCounter
lCounter = 0
last = c
elif c == 'R' and last != 'R' : # R
cols += lCounter + 1
lCounter = 0
last = 'S'
return cols
class Solution:
def countCollisions(self, directions: str) -> int:
directions = directions.lstrip('L').rstrip('R')
return len(directions) - directions.count('S')