1041. Robot Bounded In Circle (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution(object):
    def isRobotBounded(self, instructions):
        """
        :type instructions: str
        :rtype: bool
        """
        e, n = 0, 1
        x, y = 0, 0
        for c in instructions:
            if c == "G":
                x, y = x + e, y + n
            elif c == "L":
                e, n = -n, e
            elif c == "R":
                e, n = n, -e
        return (x, y) == (0, 0) or not (e, n) == (0, 1)