File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,34 @@ var permuteUnique = function (nums) {
292292
293293```
294294
295+ ### TypeScript
296+
297+ ``` typescript
298+ function permuteUnique(nums : number []): number [][] {
299+ nums .sort ((a , b ) => a - b );
300+ const resArr: number [][] = [];
301+ const usedArr: boolean [] = new Array (nums .length ).fill (false );
302+ backTracking (nums , []);
303+ return resArr ;
304+ function backTracking(nums : number [], route : number []): void {
305+ if (route .length === nums .length ) {
306+ resArr .push (route .slice ());
307+ return ;
308+ }
309+ for (let i = 0 , length = nums .length ; i < length ; i ++ ) {
310+ if (i > 0 && nums [i ] === nums [i - 1 ] && usedArr [i - 1 ] === false ) continue ;
311+ if (usedArr [i ] === false ) {
312+ route .push (nums [i ]);
313+ usedArr [i ] = true ;
314+ backTracking (nums , route );
315+ usedArr [i ] = false ;
316+ route .pop ();
317+ }
318+ }
319+ }
320+ };
321+ ```
322+
295323### Swift
296324
297325``` swift
You can’t perform that action at this time.
0 commit comments