297 序列化/反序列化二叉树
1 | private static final String spliter = ","; |
652 重复子树
114 Flatten Binary Tree to Linked List
1 | in: |
用一个全局变量保存右边flatten好的根节点,移动到当前flatten节点的右边。
后序遍历,并且先右节点再左节点。1
2
3
4
5
6
7
8
9TreeNode prev = null;
public void flatten(TreeNode root) {
if(root == null)return;
flatten(root.right);
flatten(root.left);
root.right = prev;
root.left = null;
prev = root;
}
513. Find Bottom Left Tree Value
Input:1
2
3
4
5
6
7 1
/ \
2 3
/ / \
4 5 6
/
7
Output:
7
1 | public int findBottomLeftValue(TreeNode root) { |