Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. 



The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are R (Right), L (Left), U (Up) and D (down). The output should be true or false representing whether the robot makes a circle.


Example 1:

Input: "UD"
Output: true



Example 2:

Input: "LL"
Output: false

Difficulty: introductory

Starter code:

class Solution:
    def judgeCircle(self, moves: str) -> bool:


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

class Solution:
     def judgeCircle(self, moves):
         """
         :type moves: str
         :rtype: bool
         """
         if not moves:
             return True
         if len(moves) % 2 == 1:
             return False
         
         up, left = 0, 0
         for move in moves:
             if move == 'U':
                 up += 1
             if move == 'D':
                 up -= 1
             if move == 'L':
                 left += 1
             if move == 'R':
                 left -= 1
         return up == 0 and left == 0
             


class Solution:
     def judgeCircle(self, moves):
         """
         :type moves: str
         :rtype: bool
         """
         pos = [0,0]
         for i in moves:
             if i == 'U':
                 pos[0] = pos[0] + 1
             elif i == 'D':
                 pos[0] = pos[0] - 1
             elif i == 'L':
                 pos[1] = pos[1] - 1
             elif i == 'R':
                 pos[1] = pos[1] + 1
         return [0,0] == pos

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


class Solution:
     def judgeCircle(self, moves):
         l, r, u, d = list(map(moves.count, 'LRUD'))
         return l == r and u == d


class Solution:
     def judgeCircle(self, moves):
         """
         :type moves: str
         :rtype: bool
         """
 
        # moves = list(moves)
        # u = moves.count('U')
        # d = moves.count('D')
        # l = moves.count('L')
        # r = moves.count('R')
        # if u == d and l == r:
        #     return True
        # else:
        #     return False
        # return moves.count('L') == moves.count('R') and moves.count('U') == moves.count('D')
         u, d, l, r = map(moves.count, 'UDLR')
         return u==d and l==r

class Solution:
     def judgeCircle(self, moves):
         m_list = list(moves)
         return m_list.count('U') == m_list.count('D') and m_list.count('R') == m_list.count('L')


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