class Solution {
public:
bool isRobotBounded(string instructions) {
int visited[101][101];
int x=0,y=0,dir=0; //e(0),w(1),s(2),n(3)
int cnt=4;
while(cnt--){
for(int i=0; i<instructions.length(); i++){
int cmd=instructions[i];
if(cmd=='G'){
if(dir==0) y+=1;
if(dir==1) x-=1;
if(dir==2) y-=1;
if(dir==3) x+=1;
}
if(cmd=='L'){
dir+=1;
if(dir>3) dir=0;
}
if(cmd=='R'){
dir-=1;
if(dir<0) dir=3;
}
}
if(x==0&&y==0) return true;
}
return false;
}
};
'Algorithm ๐ง๐ปโ๐ป > Leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Leetcode,c++] Search Insert Position (0) | 2021.11.09 |
---|---|
[Leetcode,c++] Find the City With the Smallest Number of Neighbors at a Threshold Distance (0) | 2021.11.07 |
[Leetcode,c++] Combination Sum (0) | 2021.11.07 |
[Leetcode,c++] Multiply-Strings (0) | 2021.11.07 |
[Leetcode,c++] Longest Common Subsequence (0) | 2021.10.23 |
[Leetcode,c++] Two Sum (0) | 2021.10.23 |
๋๊ธ