判断10步能不能回到原点

Posted wlj-axia

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断10步能不能回到原点相关的知识,希望对你有一定的参考价值。

题目描述:

# 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步能不能回到原点的主要内容,如果未能解决你的问题,请参考以下文章

使用 UIPanGestureRecognizer 移动时图片总是回到原点

一切又回到了原点

智力题_环回到原点问题

智力题_环回到原点问题

回到前台的 iPhone 应用程序将视图移回其原点,并且键盘仍然可见

uva3983