Python solution 35ms (based on changes)


  • 0
    Y

    Python solution 35ms (based on changes)

    class Solution(object):
        def judgeCircle(self, moves):
            """
            :type moves: str
            :rtype: bool
            """
            if len(moves)%2 == 0:
                return moves.count('U')==moves.count('D') and moves.count('R')==moves.count('L')
                # x = 0
                # y = 0
    
                # for move in moves:
                #     if move == 'R':
                #         x += 1
                #     elif move == 'L':
                #         x -= 1
                #     elif move == 'U':
                #         y += 1
                #     elif move == 'D':
                #         y -= 1
                #     else:
                #         print move, 'unknown'
                #         return False
                # if x == 0 and y == 0:
                #     return True
                # else:
                #     return False
            
            else:
                return False
    

    0_1508255718683_6a75436f-5012-46e6-a913-5742f61c181e-image.png


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.