/*
* @lc app=leetcode id=1041 lang=cpp
*
* [1041] Robot Bounded In Circle
*/
// @lc code=start
class Solution {
public:
bool isRobotBounded(string str) {
int x = 0, y = 0;
vector<int> dirx = {-1, 0, 1, 0};
vector<int> diry = {0, -1, 0, 1};
int xLoc = 0, yLoc = 0;
int N = str.length();
for(int k=0;k<4;k++){
for(int i=0;i<N;i++){
if(str[i] == 'G'){
x += dirx[xLoc];
y += diry[yLoc];
}else if(str[i] == 'L'){
xLoc = (xLoc + 1)%4;
yLoc = (yLoc + 1)%4;
}else if(str[i] == 'R'){
xLoc = (xLoc + 3)%4;
yLoc = (yLoc + 3)%4;
}
}
}
if(x == 0 && y == 0){
return true;
}
return false;
}
};
// @lc code=end
No.277 - LeetCode[1041] Robot Bounded In Circle - 模拟题
最新推荐文章于 2024-04-26 09:02:35 发布