通常,一个“bottom-up”函数bottom_up(root)如下所示: 1.returnspecific valuefornull node2. left_ans = bottom_up(root.left) // call function recursivelyforleft child3. right_ans = bottom_up(root.right) // call function recursivelyforright child4.returnanswers // answer <-- left_ans, right...
public class TreeNode { int val; //值 TreeNode left; //左子树 TreeNode right; //右子树 TreeNode() { } TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) { this.val = val; this.left = left; this.right = right; } } 1. 2. 3. 4. ...
Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7...
Binary Tree Right Side View 中文网站:199. 二叉树的右视图 问题描述 Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example 1: Input: root = [1,2,3,null,5,null,4] Output: ...
return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ] 1. 2. 3. 4. 5. # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None ...
0199 Binary Tree Right Side View Go 61.1% Medium 0200 Number of Islands Go 56.1% Medium 0201 Bitwise AND of Numbers Range Go 42.2% Medium 0202 Happy Number Go 54.3% Easy 0203 Remove Linked List Elements Go 44.7% Easy 0204 Count Primes Go 33.1% Medium 0205 Isomorphic Strings Go ...
26 SubstructureInTree 树的子结构 Java 27 MirrorOfBinaryTree 二叉树的镜像 Java 28 SymmetricalBinaryTree 对称的二叉树 Java 29 PrintMatrix 顺时针打印矩阵 Java 30 MinInStack 包含min 函数的栈 Java 31 StackPushPopOrder 栈的压入、弹出序列 Java 32_01 PrintTreeFromTopToBottom 不分行从上往下打印二叉树...
You are asked to cut off all the trees in this forest in the order of tree's height - always cut off the tree with lowest height first. And after cutting, the original place has the tree will become a grass (value 1). You will start from the point (0, 0)and you should output ...
95. Unique Binary Search Trees II 递归的思路,对于1..n,我们分别以1到n为根结点,然后左边的树构建左子树,右边的树构建右子树,然后左右子树两两结合,这个过程可以用递归来完成。 /** * Definition for a binary tree node. * public class TreeNode { ...
public List<List<Integer>> levelOrderBottom(TreeNode root) { List<List<Integer>> res = new ArrayList<>(); if(root == null) return res; Queue<TreeNode> q = new LinkedList<>(); q.offer(root); while(!q.isEmpty()){ List<Integer> tmp = new ArrayList<>(); int n = q.size();...