mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
657.机器人能否返回原点 添加python3版本
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user