Plain python solution


  • 0
    I
    def judgeCircle(self, moves):
            """
            :type moves: str
            :rtype: bool
            """
            dist_x, dist_y = 0, 0
            mapping = {'U': (0, 1), 'D': (0, -1), 'L': (-1, 0), 'R': (1, 0)}
            for move in moves:
                inc_x, inc_y = mapping[move]
                dist_x, dist_y = dist_x + inc_x, dist_y + inc_y
            return dist_x == 0 and dist_y == 0
    

Log in to reply
 

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