124 ms
classSolution(object):defjudgeCircle(self, moves):"""
:type moves: str
:rtype: bool
"""
x =0
y =0for i in moves:if i =="U":
y +=1elif i =="D":
y +=-1elif i =="L":
x +=-1elif i =="R":
x +=1if x ==0and y ==0:returnTrueelse:returnFalse
python
32 ms
classSolution(object):defjudgeCircle(self, moves):"""
:type moves: str
:rtype: bool
"""
l = moves.count('L')
r = moves.count('R')
u = moves.count('U')
d = moves.count('D')if l==r and u==d:returnTrueelse:returnFalse