657. Robot Return to Origin

Information

  • Diffculty: Easy

  • Created: 2019-09-03 00:03:26

  • Last Motified: 2019-09-03 00:03:26

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