题目描述   Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. /** * Definition for binary tree * public class TreeNode { * int…

2019年7月13日 0条评论 33点热度 阅读全文

题目描述   Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. /** * Definition for binary tree * public class TreeNode { * int…

2019年7月13日 0条评论 17点热度 阅读全文

An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(1); push(2); push(3); pop(); pop(); p…

2019年5月29日 0条评论 22点热度 阅读全文

An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(1); push(2); push(3); pop(); pop(); p…

2019年5月29日 0条评论 32点热度 阅读全文

public static TreeNode create(int[] post, int postLeft, int postRight, int[] in, int inLeft, int inRight) { if (postLeft > postRight) { return null; } TreeNode root = new TreeNode(post[postRight]); // 从中序遍历中找出根节点 int findIndex = -1; for (int i=inLeft; i<…

2019年5月29日 0条评论 26点热度 阅读全文

public static TreeNode create(int[] post, int postLeft, int postRight, int[] in, int inLeft, int inRight) { if (postLeft > postRight) { return null; } TreeNode root = new TreeNode(post[postRight]); // 从中序遍历中找出根节点 int findIndex = -1; for (int i=inLeft; i<…

2019年5月29日 0条评论 17点热度 阅读全文

从上到下按层打印二叉树,同一层结点从左至右输出。每一层输出一行。 import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; /* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public clas…

2019年5月28日 0条评论 21点热度 阅读全文

从上到下按层打印二叉树,同一层结点从左至右输出。每一层输出一行。 import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; /* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public clas…

2019年5月28日 0条评论 20点热度 阅读全文

/* class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public TreeNode copyTreeNode(TreeNode root) { TreeNode copyRoot = null; if (root != null) { copyRoot = new TreeNode (root.val); copy…

2019年5月28日 0条评论 24点热度 阅读全文

/* class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public TreeNode copyTreeNode(TreeNode root) { TreeNode copyRoot = null; if (root != null) { copyRoot = new TreeNode (root.val); copy…

2019年5月28日 0条评论 30点热度 阅读全文