Furthest Point From Origin
You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.
In the i^th move, you can choose one of the following directions:
- Move to the left if
moves[i] = 'L'ormoves[i] = '_'. - Move to the right if
moves[i] = 'R'ormoves[i] = '_'.
Return the distance from the origin of the furthest point you can get to after n moves.
Example 1
Input
moves = "L_RL__R"Output
3The furthest point we can reach from the origin 0 is point -3 through the sequence of moves "LLRLLLR".
Example 2
Input
moves = "_R__LL_"Output
5The furthest point we can reach from the origin 0 is point -5 through the sequence of moves "LRLLLLL".
Constraints
- 1 <= moves.length == n <= 50
- moves consists only of characters 'L', 'R' and '_'.