Skip to content

Commit f99976e

Browse files
authored
Create furthest-point-from-origin.py
1 parent 11c0ea4 commit f99976e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/furthest-point-from-origin.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# math
5+
class Solution(object):
6+
def furthestDistanceFromOrigin(self, moves):
7+
"""
8+
:type moves: str
9+
:rtype: int
10+
"""
11+
curr = cnt = 0
12+
for x in moves:
13+
if x == 'L':
14+
curr -= 1
15+
elif x == 'R':
16+
curr += 1
17+
else:
18+
cnt += 1
19+
return abs(curr)+cnt

0 commit comments

Comments
 (0)