Skip to content

Commit e0e0df7

Browse files
committed
Time: 0 ms (100.00%), Space: 6.1 MB (73.34%) - LeetHub
1 parent f99318d commit e0e0df7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public:
3+
// N E S W
4+
// 0 1 2 3
5+
vector<vector<int>> dirs = {
6+
{0, 1},
7+
{1, 0},
8+
{0, -1},
9+
{-1, 0}
10+
};
11+
12+
bool isRobotBounded(string instr) {
13+
int x = 0, y = 0, d = 0;
14+
for(auto ch: instr){
15+
switch(ch) {
16+
case 'G':
17+
x += dirs[d][0];
18+
y += dirs[d][1];
19+
break;
20+
case 'R':
21+
d = (d + 1) % 4;
22+
break;
23+
case 'L':
24+
d = (d - 1 + 4) % 4;
25+
break;
26+
}
27+
}
28+
29+
return (x == 0 and y == 0) || d;
30+
}
31+
};

0 commit comments

Comments
 (0)