File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed
Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -14,20 +14,21 @@ var threeSum = function(nums) {
1414 const numsLength = nums . length
1515 if ( numsLength == 3 && nums . reduce ( ( a , b ) => a + b , 0 ) == 0 ) return [ nums ]
1616
17- const ret = [ ]
18- const seen = new Set ( ) ;
17+ const ret = [ ]
18+ const seen = new Set ( ) ;
1919 nums . sort ( ( a , b ) => a - b ) ;
20+
2021 function dfs ( arr , start , dep ) {
2122 if ( dep == 3 ) {
22- if ( arr . length !== 3 ) return
23- const arrTotal = arr . reduce ( ( a , b ) => a + b , 0 ) ;
24- if ( arrTotal == 0 ) {
25- const string = [ ...arr ] . sort ( ( a , b ) => a - b ) . join ( ',' )
26- if ( ! seen . has ( string ) ) {
27- seen . add ( string )
28- ret . push ( arr )
29- }
30- }
23+ if ( arr . length !== 3 ) return
24+ const arrTotal = arr . reduce ( ( a , b ) => a + b , 0 ) ;
25+ if ( arrTotal == 0 ) {
26+ const string = [ ...arr ] . sort ( ( a , b ) => a - b ) . join ( ',' )
27+ if ( ! seen . has ( string ) ) {
28+ seen . add ( string )
29+ ret . push ( arr )
30+ }
31+ }
3132 return
3233 }
3334 //만약 start가 0이 되면, i를 감소시켜야하고, 새로운 배열을 추가해야한다. 기존의 배열에 넣어주는게 아니다.
You can’t perform that action at this time.
0 commit comments