1 class Solution: 2 def isRobotBounded(self, instructions: str) -> bool: 3 vec = [0,0,0] 4 #0 up(north),1 left(west),2 down(south),3 right(east) 5 for ins in instructions: 6 if ins == 'G': 7 if vec[2] == 0: 8 vec[1] += 1 9 elif vec[2] == 1: 10 vec[0] -= 1 11 elif vec[2] == 2: 12 vec[1] -= 1 13 else: 14 vec[0] += 1 15 elif ins =='L': 16 vec[2] = (vec[2] + 1) % 4 17 elif ins == 'R': 18 vec[2] = (vec[2] +3) % 4 19 #print(vec) 20 if vec[0]==0 and vec[1]==0: 21 return True 22 elif vec[2] != 0: 23 return True 24 else : 25 return False
这是什么数学原理呢?想不出来。GG GL,这道题的灵感是从魔兽来的么。。。