Robot Return to Origin

Problem Id: 657 Difficulty: Easy


Intuition

Solution


class Solution:
    def judgeCircle(self, moves: str) -> bool:
        x, y = 0, 0
        for m in moves:
            if m == 'R':
                y += 1
            elif m == 'L':
                y -= 1
            elif m == 'U':
                x += 1
            else:
                x -= 1
        return x == y == 0