File tree 3 files changed +88
-0
lines changed
solution/0800-0899/0816.Ambiguous Coordinates
3 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,37 @@ func ambiguousCoordinates(s string) []string {
191
191
}
192
192
```
193
193
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
+
194
225
### ** ...**
195
226
196
227
```
Original file line number Diff line number Diff line change @@ -169,6 +169,37 @@ func ambiguousCoordinates(s string) []string {
169
169
}
170
170
```
171
171
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
+
172
203
### ** ...**
173
204
174
205
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments