File tree 1 file changed +17
-17
lines changed
1 file changed +17
-17
lines changed Original file line number Diff line number Diff line change 10
10
* @return {TreeNode[] }
11
11
*/
12
12
const generateTrees = function ( n ) {
13
- if ( n === 0 ) return [ ]
14
- return genTreeList ( 1 , n ) ;
15
- } ;
13
+ if ( n === 0 ) return [ ]
14
+ return genTreeList ( 1 , n )
15
+ }
16
16
17
17
function genTreeList ( start , end ) {
18
- const list = [ ]
19
- if ( start > end ) list . push ( null )
20
- for ( let idx = start ; idx <= end ; idx ++ ) {
21
- const leftList = genTreeList ( start , idx - 1 )
22
- const rightList = genTreeList ( idx + 1 , end )
23
- for ( let left of leftList ) {
24
- for ( let right of rightList ) {
25
- const root = new TreeNode ( idx )
26
- root . left = left
27
- root . right = right
28
- list . push ( root )
29
- }
30
- }
18
+ const list = [ ]
19
+ if ( start > end ) list . push ( null )
20
+ for ( let idx = start ; idx <= end ; idx ++ ) {
21
+ const leftList = genTreeList ( start , idx - 1 )
22
+ const rightList = genTreeList ( idx + 1 , end )
23
+ for ( let left of leftList ) {
24
+ for ( let right of rightList ) {
25
+ const root = new TreeNode ( idx )
26
+ root . left = left
27
+ root . right = right
28
+ list . push ( root )
29
+ }
31
30
}
32
- return list
31
+ }
32
+ return list
33
33
}
You can’t perform that action at this time.
0 commit comments