File tree 1 file changed +6
-6
lines changed
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 17
17
var leafSimilar = function ( root1 , root2 ) {
18
18
19
19
const dfs = ( node , arr ) => {
20
- if ( ! node . left && ! node . right ) {
20
+ if ( ! node . left && ! node . right ) {
21
21
arr . push ( node . val ) ;
22
22
return arr ;
23
23
}
24
- if ( node . left ) dfs ( node . left , arr ) ;
25
- if ( node . right ) dfs ( node . right , arr ) ;
24
+ if ( node . left ) dfs ( node . left , arr ) ;
25
+ if ( node . right ) dfs ( node . right , arr ) ;
26
26
27
27
return arr ;
28
28
}
29
29
30
30
const arr1 = dfs ( root1 , [ ] ) ;
31
31
const arr2 = dfs ( root2 , [ ] ) ;
32
32
33
- if ( arr1 . length !== arr2 . length ) return false ;
33
+ if ( arr1 . length !== arr2 . length ) return false ;
34
34
35
- for ( let i = 0 ; i < arr1 . length ; i ++ ) {
36
- if ( arr1 [ i ] !== arr2 [ i ] ) return false ;
35
+ for ( let i = 0 ; i < arr1 . length ; i ++ ) {
36
+ if ( arr1 [ i ] !== arr2 [ i ] ) return false ;
37
37
}
38
38
39
39
return true ;
You can’t perform that action at this time.
0 commit comments