Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DIRS = [
- (1,0),
- (0,1),
- (-1,0),
- (0,-1),
- ]
- class Solution:
- def isRobotBounded(self, instructions: str) -> bool:
- d = 0
- px = py = 0
- for c in instructions:
- if c == "G":
- px += DIRS[d][0]
- py += DIRS[d][1]
- else:
- d += 1 if c == "L" else 3
- d %= 4
- #print(d, px, py)
- if px == py == 0:
- return True
- if d == 0:
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement