657. 机器人能否返回原点
python机器人能否返回原点124 msclass Solution(object):def judgeCircle(self, moves):""":type moves: str:rtype: bool"""x = 0y = 0for i in m...
·
python
- 机器人能否返回原点
124 ms
class Solution(object):
def judgeCircle(self, moves):
"""
:type moves: str
:rtype: bool
"""
x = 0
y = 0
for i in moves:
if i == "U":
y +=1
elif i == "D":
y +=-1
elif i == "L":
x +=-1
elif i == "R":
x +=1
if x ==0 and y == 0:
return True
else:
return False
python
32 ms
class Solution(object):
def judgeCircle(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:
return True
else:
return False
更多推荐
所有评论(0)