657.机器人能否返回原点 添加python3版本

This commit is contained in:
posper
2021-07-31 10:20:56 +08:00
parent 58ed197ba9
commit 4764d993b2

View File

@ -91,6 +91,20 @@ class Solution {
## Python ## Python
```python ```python
class Solution:
def judgeCircle(self, moves: str) -> bool:
x = 0 # 记录当前位置
y = 0
for i in range(len(moves)):
if (moves[i] == 'U'):
y += 1
if (moves[i] == 'D'):
y -= 1
if (moves[i] == 'L'):
x += 1
if (moves[i] == 'R'):
x -= 1
return x == 0 and y == 0
``` ```
## Go ## Go