此篇文章為我的解題紀錄,程式碼或許並不是很完善

Leetcode - 657. Robot Return to Origin

解題思路

verhor來模擬(x,y)座標,看最後是否在(0,0)座標上。

我滴程式碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
def judgeCircle(self, moves: str) -> bool:
ver = 0
hor = 0
for i in moves:
if i == "L":
hor = hor - 1
elif i == "R":
hor = hor + 1
elif i == "U":
ver = ver + 1
else:
ver = ver - 1
if ver == 0 and hor == 0:
return True
else:
return False