Skip to content

Commit 1f45187

Browse files
committed
feat: add typescript solution to lc problem: No.0657
No.0657.Robot Return to Origin
1 parent 0085946 commit 1f45187

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/0600-0699/0657.Robot Return to Origin/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ class Solution {
7272
}
7373
```
7474

75+
### **TypeScript**
76+
77+
```ts
78+
function judgeCircle(moves: string): boolean {
79+
let x = 0, y = 0;
80+
const dir = {
81+
R: [1, 0],
82+
L: [-1, 0],
83+
U: [0, 1],
84+
D: [0, -1]
85+
};
86+
for (let u of moves) {
87+
const [dx, dy] = dir[u];
88+
x += dx;
89+
y += dy;
90+
}
91+
return !x && !y;
92+
};
93+
```
94+
7595
### **...**
7696

7797
```

solution/0600-0699/0657.Robot Return to Origin/README_EN.md

+20
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ class Solution {
8989
}
9090
```
9191

92+
### **TypeScript**
93+
94+
```ts
95+
function judgeCircle(moves: string): boolean {
96+
let x = 0, y = 0;
97+
const dir = {
98+
R: [1, 0],
99+
L: [-1, 0],
100+
U: [0, 1],
101+
D: [0, -1]
102+
};
103+
for (let u of moves) {
104+
const [dx, dy] = dir[u];
105+
x += dx;
106+
y += dy;
107+
}
108+
return !x && !y;
109+
};
110+
```
111+
92112
### **...**
93113

94114
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function judgeCircle(moves: string): boolean {
2+
let x = 0, y = 0;
3+
const dir = {
4+
R: [1, 0],
5+
L: [-1, 0],
6+
U: [0, 1],
7+
D: [0, -1]
8+
};
9+
for (let u of moves) {
10+
const [dx, dy] = dir[u];
11+
x += dx;
12+
y += dy;
13+
}
14+
return !x && !y;
15+
};

0 commit comments

Comments
 (0)