File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -332,7 +332,43 @@ var threeSum = function(nums) {
332
332
return res;
333
333
};
334
334
```
335
+ TypeScript:
335
336
337
+ ``` typescript
338
+ function threeSum(nums : number []): number [][] {
339
+ nums .sort ((a , b ) => a - b );
340
+ let length = nums .length ;
341
+ let left: number = 0 ,
342
+ right: number = length - 1 ;
343
+ let resArr: number [][] = [];
344
+ for (let i = 0 ; i < length ; i ++ ) {
345
+ if (i > 0 && nums [i ] === nums [i - 1 ]) {
346
+ continue ;
347
+ }
348
+ left = i + 1 ;
349
+ right = length - 1 ;
350
+ while (left < right ) {
351
+ let total: number = nums [i ] + nums [left ] + nums [right ];
352
+ if (total === 0 ) {
353
+ resArr .push ([nums [i ], nums [left ], nums [right ]]);
354
+ left ++ ;
355
+ right -- ;
356
+ while (nums [right ] === nums [right + 1 ]) {
357
+ right -- ;
358
+ }
359
+ while (nums [left ] === nums [left - 1 ]) {
360
+ left ++ ;
361
+ }
362
+ } else if (total < 0 ) {
363
+ left ++ ;
364
+ } else {
365
+ right -- ;
366
+ }
367
+ }
368
+ }
369
+ return resArr ;
370
+ };
371
+ ```
336
372
337
373
ruby:
338
374
``` ruby
You can’t perform that action at this time.
0 commit comments