File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
solution/1000-1099/1041.Robot Bounded In Circle Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,28 @@ func isRobotBounded(instructions string) bool {
178
178
}
179
179
```
180
180
181
+ ### **TypeScript**
182
+
183
+ ```ts
184
+ function isRobotBounded(instructions: string): boolean {
185
+ const direction = new Array(4).fill(0);
186
+ let cur = 0;
187
+ for (const c of instructions.split('')) {
188
+ if (c === 'L') {
189
+ cur = (cur + 1) % 4;
190
+ } else if (c === 'R') {
191
+ cur = (cur + 3) % 4;
192
+ } else {
193
+ ++direction[cur];
194
+ }
195
+ }
196
+ return (
197
+ cur !== 0 ||
198
+ (direction[0] === direction[2] && direction[1] === direction[3])
199
+ );
200
+ }
201
+ ```
202
+
181
203
### **...**
182
204
183
205
```
Original file line number Diff line number Diff line change @@ -163,6 +163,28 @@ func isRobotBounded(instructions string) bool {
163
163
}
164
164
```
165
165
166
+ ### **TypeScript**
167
+
168
+ ```ts
169
+ function isRobotBounded(instructions: string): boolean {
170
+ const direction = new Array(4).fill(0);
171
+ let cur = 0;
172
+ for (const c of instructions.split('')) {
173
+ if (c === 'L') {
174
+ cur = (cur + 1) % 4;
175
+ } else if (c === 'R') {
176
+ cur = (cur + 3) % 4;
177
+ } else {
178
+ ++direction[cur];
179
+ }
180
+ }
181
+ return (
182
+ cur !== 0 ||
183
+ (direction[0] === direction[2] && direction[1] === direction[3])
184
+ );
185
+ }
186
+ ```
187
+
166
188
### **...**
167
189
168
190
```
Original file line number Diff line number Diff line change
1
+ function isRobotBounded(instructions: string): boolean {
2
+ const direction = new Array(4).fill(0);
3
+ let cur = 0;
4
+ for (const c of instructions.split('')) {
5
+ if (c === 'L') {
6
+ cur = (cur + 1) % 4;
7
+ } else if (c === 'R') {
8
+ cur = (cur + 3) % 4;
9
+ } else {
10
+ ++direction[cur];
11
+ }
12
+ }
13
+ return (
14
+ cur !== 0 ||
15
+ (direction[0] === direction[2] && direction[1] === direction[3])
16
+ );
17
+ }
You can’t perform that action at this time.
0 commit comments