—Easy
https://leetcode.com/problems/robot-return-to-origin/
Code:
class Solution: def judgeCircle(self, moves: str) -> bool: count_h = 0 count_v = 0 for char in moves: if char == 'U': count_h -= 1 if char == 'D': count_h += 1 if char == 'L': count_v -= 1 if char == 'R': count_v += 1 if count_v == 0 and count_h == 0: return True else: return False # s = Solution() # print(s.judgeCircle("LL"))
思路:
1.遍历计数
2.map or dict