Wednesday, November 22, 2017

657. Judge Route Circle

class Solution:
    def judgeCircle(self, moves):
        """
        :type moves: str
        :rtype: bool
        """
        num1 = 0
        num2 = 0
        for i in moves:
            if i == "R":
                num1 += 1
            if i == "L":
                num1 -= 1
            if i == "U":
                num2 += 1
            if i == "D":
                num2 -= 1
        if num1 == 0 and num2 ==0:
            return True
        else:
            return False

No comments:

Post a Comment