Easy
思路应该还是比较清晰的
以上,尝试写一下代码,AC!
python3
class Solution:
def judgeCircle(self, moves: str) -> bool:
counter = {"R":0,"L":0,"U":0,"D":0}
pairs = {"R":"L","L":"R","U":"D","D":"U"}
for m in moves:
if counter[pairs[m]] > 0:
counter[pairs[m]] -= 1
else:
counter[m] += 1
for k,v in counter.items():
if v != 0:
return False
return True