标签:nbsp for mic png style div i++ lazy tree
不是我自己写出来的,思想大概是懂的,没自己写,看了别人的代码;
public List<TreeNode> generateTrees(int n) { if(n == 0){ return new LinkedList<>(); } return generate_trees(1,n); } private LinkedList<TreeNode> generate_trees(int start, int end) { LinkedList<TreeNode> all_trees = new LinkedList<>(); if(start > end){ all_trees.add(null); return all_trees; } for(int i = start;i<=end ;i++){ LinkedList<TreeNode> left_trees = generate_trees(start,i-1); LinkedList<TreeNode> right_trees = generate_trees(i+1,end); for(TreeNode l : left_trees){ for(TreeNode r : right_trees){ TreeNode current_tree = new TreeNode(i); current_tree.left = l; current_tree.right = r; all_trees.addLast(current_tree); } } } return all_trees; }
——2020.7.1
标签:nbsp for mic png style div i++ lazy tree
原文地址:https://www.cnblogs.com/taoyuxin/p/13221626.html