class Solution:
def judgeCircle(self, moves):
"""
:type moves: str
:rtype: bool
"""
m=moves.count("U")
n=moves.count("D")
j=moves.count("L")
k=moves.count("R")
return m==n and j==k
leetcode - 657 - 机器人能否返回原点
本文介绍了一种简单而有效的算法,用于判断给定的一系列移动指令是否使机器人回到原点,形成一个完整的圆形路径。通过计数不同方向的移动次数,可以轻松确定最终位置是否与起点重合。

被折叠的 条评论
为什么被折叠?



