Skip to content

Commit 92f4507

Browse files
committed
update 95
1 parent 6f0fe0c commit 92f4507

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

95-unique-binary-search-trees-ii.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010
* @return {TreeNode[]}
1111
*/
1212
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+
}
1616

1717
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+
}
3130
}
32-
return list
31+
}
32+
return list
3333
}

0 commit comments

Comments
 (0)