Easy
Furthest Point From Origin — Python
Full explanation · Time O(1) · Space O(1)
# Time: O(n)
# Space: O(1)
# math
class Solution(object):
def furthestDistanceFromOrigin(self, moves):
"""
:type moves: str
:rtype: int
"""
curr = cnt = 0
for x in moves:
if x == 'L':
curr -= 1
elif x == 'R':
curr += 1
else:
cnt += 1
return abs(curr)+cnt