Skip to content

Commit 4f1fd24

Browse files
committed
feat: add solutions to lc problems: No.1041
1 parent 0ada84f commit 4f1fd24

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

solution/1000-1099/1041.Robot Bounded In Circle/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ func isRobotBounded(instructions string) bool {
178178
}
179179
```
180180

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+
181203
### **...**
182204

183205
```

solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md

+22
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@ func isRobotBounded(instructions string) bool {
163163
}
164164
```
165165

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+
166188
### **...**
167189

168190
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)