码迷,mamicode.com
首页 > 其他好文 > 详细

判断10步能不能回到原点

时间:2020-04-06 00:16:25      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:ret   eve   minutes   nes   with   ISE   and   ide   only   

题目描述:

# You live in the city of Cartesia where all roads are laid out in a perfect grid.
# You arrived ten minutes too early to an appointment, so you decided
# to take the opportunity to go for a short walk. The city provides
# its citizens with a Walk Generating App on their phones --
# everytime you press the button it sends you an array of
# one-letter strings representing directions to walk
# (eg. [‘n‘, ‘s‘, ‘w‘, ‘e‘]). You always walk only a single block in a direction
# and you know it takes you one minute to traverse one city block,
# so create a function that will return true if the walk the app gives you will
# take you exactly ten minutes (you don‘t want to be early or late!) and will, of course,
# return you to your starting point. Return false otherwise.

我的解答:
def is_valid_walk(walk):
if len(walk) != 10:
return False
if walk.count(‘n‘) == walk.count(‘s‘):
if walk.count(‘w‘) == walk.count(‘e‘):
return True
return False



判断10步能不能回到原点

标签:ret   eve   minutes   nes   with   ISE   and   ide   only   

原文地址:https://www.cnblogs.com/wlj-axia/p/12639831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!