File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -420,6 +420,40 @@ var letterCombinations = function(digits) {
420420};
421421```
422422
423+ ## TypeScript
424+
425+ ``` typescript
426+ function letterCombinations(digits : string ): string [] {
427+ if (digits === ' ' ) return [];
428+ const strMap: { [index : string ]: string [] } = {
429+ 1 : [],
430+ 2 : [' a' , ' b' , ' c' ],
431+ 3 : [' d' , ' e' , ' f' ],
432+ 4 : [' g' , ' h' , ' i' ],
433+ 5 : [' j' , ' k' , ' l' ],
434+ 6 : [' m' , ' n' , ' o' ],
435+ 7 : [' p' , ' q' , ' r' , ' s' ],
436+ 8 : [' t' , ' u' , ' v' ],
437+ 9 : [' w' , ' x' , ' y' , ' z' ],
438+ }
439+ const resArr: string [] = [];
440+ function backTracking(digits : string , curIndex : number , route : string []): void {
441+ if (curIndex === digits .length ) {
442+ resArr .push (route .join (' ' ));
443+ return ;
444+ }
445+ let tempArr: string [] = strMap [digits [curIndex ]];
446+ for (let i = 0 , length = tempArr .length ; i < length ; i ++ ) {
447+ route .push (tempArr [i ]);
448+ backTracking (digits , curIndex + 1 , route );
449+ route .pop ();
450+ }
451+ }
452+ backTracking (digits , 0 , []);
453+ return resArr ;
454+ };
455+ ```
456+
423457## C
424458
425459``` c
You can’t perform that action at this time.
0 commit comments