摘要:
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.给出树的前序和中序遍历序列,构... 阅读全文
摘要:
1:前序遍历(根,左,右)递归的方法很简单:public static void pr(TreeNode root){ if(root!=null){ System.out.println(root.val); pr(root.left); pr(root.right); }} 非递归的方法:... 阅读全文
摘要:
相当与剑指offer上的面试题19求二叉树的镜像。先前序遍历这棵树的每个结点,如果遍历到的结点有子节点,就交换他的两个子节点,当交换完所有非叶子节点的左右子节点之后,就得到了该二叉树的镜像代码:public TreeNode invertTree(TreeNode root) { i... 阅读全文