The code here is a solution that beats 86% other solutions.
class Solution(object): def judgeCircle(self, moves): """ judgeCircle :type moves: str :rtype: bool """ x = moves.count("R") - moves.count("L") y = moves.count("U") - moves.count("D") return x == 0 and y == 0
Basically the information where the robot goes is not important at all. Important is to notice that if the robot goes Up, it has to go down. The solution is to simply sum Up and Down, Left and Right moves to see if those result in zeros.