Skip to content

Commit f4d2492

Browse files
committed
Runtime: 89 ms (Top 60.33%) | Memory: 42.1 MB (Top 68.87%)
1 parent d06ed38 commit f4d2492

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 89 ms (Top 60.33%) | Memory: 42.1 MB (Top 68.87%)
12
var isRobotBounded = function(instructions) {
23
// north = 0, east = 1, south = 2, west = 3
34
let directions = [[0, 1], [1, 0], [0, -1], [-1, 0]];
@@ -6,20 +7,20 @@ var isRobotBounded = function(instructions) {
67
// facing north
78
let idx = 0;
89
let movements = [...instructions];
9-
10+
1011
for (let move of movements) {
1112
if (move == 'L')
1213
idx = (idx + 3) % 4;
1314
else if (move == 'R')
1415
idx = (idx + 1) % 4;
1516
else {
1617
x += directions[idx][0];
17-
y += directions[idx][1];
18-
}
18+
y += directions[idx][1];
19+
}
1920
}
20-
21+
2122
// after one cycle:
2223
// robot returns into initial position
2324
// or robot doesn't face north
2425
return (x == 0 && y == 0) || (idx != 0);
25-
};
26+
};

0 commit comments

Comments
 (0)