Leetcode-Easy 657. Judge Route Circle

657. Judge Route Circle

  • 描述:
    题目很简单,就是判断路线能否组成一圈。向“右”走的步数一定要等于向“左”走的步数;向“下”走的步数一定要等于向“上”走的步数。


    Leetcode-Easy 657. Judge Route Circle_第1张图片
  • 思路:
    思路就是判断下字符串中“R”的个数是否等于“L”的个数,“D”和“U”同理

  • 代码

class Solution(object):
    def judgeCircle(self, moves):
        """
        :type moves: str
        :rtype: bool
        """
        return moves.count('R')==moves.count('L') and moves.count('D')==moves.count('U')

你可能感兴趣的:(Leetcode-Easy 657. Judge Route Circle)