Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 524 Bytes

untitled-4.md

File metadata and controls

24 lines (20 loc) · 524 Bytes

1041. Robot Bounded In Circle

{% tabs %} {% tab title="Python" %}

class Solution:
    def isRobotBounded(self, instructions: str) -> bool:
        start = [0,0]
        dx, dy = 0,1
        
        for s in instructions:
            if s == "G":
                start[0] += dx
                start[1] += dy
            elif s =="L":
                dx, dy = -dy, dx
            else:
                dx, dy = dy, -dx
        
        return start == [0,0] or (dx, dy) != (0,1)

{% endtab %} {% endtabs %}