Skip to content

Commit 88da1c4

Browse files
committed
feat: add ts solution to lc problem: No.0816
No.0816.Ambiguous Coordinates
1 parent c3e2625 commit 88da1c4

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

solution/0800-0899/0816.Ambiguous Coordinates/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,37 @@ func ambiguousCoordinates(s string) []string {
191191
}
192192
```
193193

194+
### **TypeScript**
195+
196+
```ts
197+
function ambiguousCoordinates(s: string): string[] {
198+
s = s.slice(1, s.length - 1);
199+
const n = s.length;
200+
const dfs = (s: string) => {
201+
const res: string[] = [];
202+
for (let i = 1; i < s.length; i++) {
203+
const t = `${s.slice(0, i)}.${s.slice(i)}`;
204+
if (`${Number(t)}` === t) {
205+
res.push(t);
206+
}
207+
}
208+
if (`${Number(s)}` === s) {
209+
res.push(s);
210+
}
211+
return res;
212+
};
213+
const ans: string[] = [];
214+
for (let i = 1; i < n; i++) {
215+
for (const left of dfs(s.slice(0, i))) {
216+
for (const right of dfs(s.slice(i))) {
217+
ans.push(`(${left}, ${right})`);
218+
}
219+
}
220+
}
221+
return ans;
222+
}
223+
```
224+
194225
### **...**
195226

196227
```

solution/0800-0899/0816.Ambiguous Coordinates/README_EN.md

+31
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,37 @@ func ambiguousCoordinates(s string) []string {
169169
}
170170
```
171171

172+
### **TypeScript**
173+
174+
```ts
175+
function ambiguousCoordinates(s: string): string[] {
176+
s = s.slice(1, s.length - 1);
177+
const n = s.length;
178+
const dfs = (s: string) => {
179+
const res: string[] = [];
180+
for (let i = 1; i < s.length; i++) {
181+
const t = `${s.slice(0, i)}.${s.slice(i)}`;
182+
if (`${Number(t)}` === t) {
183+
res.push(t);
184+
}
185+
}
186+
if (`${Number(s)}` === s) {
187+
res.push(s);
188+
}
189+
return res;
190+
};
191+
const ans: string[] = [];
192+
for (let i = 1; i < n; i++) {
193+
for (const left of dfs(s.slice(0, i))) {
194+
for (const right of dfs(s.slice(i))) {
195+
ans.push(`(${left}, ${right})`);
196+
}
197+
}
198+
}
199+
return ans;
200+
}
201+
```
202+
172203
### **...**
173204

174205
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function ambiguousCoordinates(s: string): string[] {
2+
s = s.slice(1, s.length - 1);
3+
const n = s.length;
4+
const dfs = (s: string) => {
5+
const res: string[] = [];
6+
for (let i = 1; i < s.length; i++) {
7+
const t = `${s.slice(0, i)}.${s.slice(i)}`;
8+
if (`${Number(t)}` === t) {
9+
res.push(t);
10+
}
11+
}
12+
if (`${Number(s)}` === s) {
13+
res.push(s);
14+
}
15+
return res;
16+
};
17+
const ans: string[] = [];
18+
for (let i = 1; i < n; i++) {
19+
for (const left of dfs(s.slice(0, i))) {
20+
for (const right of dfs(s.slice(i))) {
21+
ans.push(`(${left}, ${right})`);
22+
}
23+
}
24+
}
25+
return ans;
26+
}

0 commit comments

Comments
 (0)