0
点赞
收藏
分享

微信扫一扫

Leetcode_Python 657 机器人能否返回原点

殇感故事 2023-04-07 阅读 47


Leetcode_Python  657 机器人能否返回原点_hash

解题思路

统计R(右),L(左),U(上)和 D(下)的步数,R与L相同,U和D相同即可

代码

class Solution:
    def judgeCircle(self, moves: str) -> bool:
        hash = {i:0 for i in {"U","D","L","R"}}
        for i in moves:
            hash["%s"%i] += 1
        if hash["U"]==hash["D"] and hash["L"]==hash["R"]:
            return True
        else:
            return False


举报

相关推荐

0 条评论