""" 0657.1 - Solution 1 - Count Moves """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def judgeCircle(self, moves: str) -> bool:
"""Robot Return to Origin Function"""
return moves.count("U") == moves.count("D") and moves.count("L") == moves.count("R")
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().judgeCircle("UD")) # True
print(Solution().judgeCircle("LL")) # False
print(Solution().judgeCircle("RRDD")) # False
print(Solution().judgeCircle("LRUD")) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0657.2 - Solution 2 - Coordinate Tracking """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def judgeCircle(self, moves: str) -> bool:
"""Robot Return to Origin Function"""
x, y = 0, 0
for move in moves:
if move == "U":
y += 1
elif move == "D":
y -= 1
elif move == "L":
x -= 1
elif move == "R":
x += 1
return x == 0 and y == 0
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().judgeCircle("UD")) # True
print(Solution().judgeCircle("LL")) # False
print(Solution().judgeCircle("RRDD")) # False
print(Solution().judgeCircle("LRUD")) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()