-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsolution.py
More file actions
16 lines (16 loc) · 385 Bytes
/
Copy pathsolution.py
File metadata and controls
16 lines (16 loc) · 385 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution:
# Time: O(n)
# Space: O(1)
def judge_circle(self, moves: str) -> bool:
x = 0
y = 0
for move in moves:
if move == "U":
y += 1
elif move == "D":
y -= 1
elif move == "L":
x -= 1
else:
x += 1
return x == 0 and y == 0