A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands: -2: turn left 90 degrees -1: turn right 90 degrees 1 <= x <= 9: move forward x units Some of the grid squares are obs…
这道题直接按照题意来解,建立坐标系和移动方案,思路是比较简单的.只是需要注意需要使用set来判断是否遇到障碍,否则会超时. int robotSim(vector<int>& commands, vector<vector<int>>& obstacles) { int N = commands.size(); int M = obstacles.size(); //向上 Wx=0,Wy=1 //向左 Wx=-1,Wy=0 //向下 Wx=0,Wy=-1…