> For the complete documentation index, see [llms.txt](https://cai-sen-se.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cai-sen-se.gitbook.io/leetcode/601-800/657.-ji-qi-ren-neng-fou-fan-hui-yuan-dian.md).

# 657. 机器人能否返回原点

<https://leetcode-cn.com/problems/robot-return-to-origin/>

## 解法一：

用两个计数器（水平、垂直）分别计算**上下**和**左右**方向的移动步数，初始都为0，若能回归初始状态，则说明返回原点

```python
class Solution:
    def judgeCircle(self, moves: str) -> bool:
        vertical = 0  #垂直方向
        horizontal = 0  #水平
        for move in moves:
            if move == 'R':
                horizontal += 1
            if move == 'L':
                horizontal -= 1
            if move == 'U':
                vertical += 1
            if move == 'D':
                vertical -= 1
        return vertical == 0 and horizontal == 0
```
