随笔分类 - Binary Tree
摘要:class Solution { public List rightSideView(TreeNode root) { List res=new ArrayList(); rightView(root, res, 0); return res; } private void rightView(TreeNode node, ...
阅读全文
摘要:class Solution { public List postorderTraversal(TreeNode root) { Stack stack=new Stack(); List res=new ArrayList(); while(root!=null||!stack.isEmpty()) { ...
阅读全文
摘要:class Solution { public List preorderTraversal(TreeNode root) { Stack stack=new Stack(); List res=new ArrayList(); while(root!=null||!stack.isEmpty()) { ...
阅读全文
摘要:class Solution { public int sumNumbers(TreeNode root) { return sumNumber("", root); } private int sumNumber(String str, TreeNode node){ if(node==null) return 0...
阅读全文
摘要:public class Solution { public void connect(TreeLinkNode root) { TreeLinkNode lstart=new TreeLinkNode(0); while(root!=null) { TreeLinkNode cur=lstart; ...
阅读全文
摘要:public class Solution { public void connect(TreeLinkNode root) { TreeLinkNode startNode=root; while(startNode!=null) { TreeLinkNode node=startNode; ...
阅读全文
摘要:class Solution { public void flatten(TreeNode root) { TreeNode cur=root, pre=null; while(cur!=null) { if(cur.left!=null) { pre=cur....
阅读全文
摘要:public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return buildTree(inorder, 0, inorder.length-1, postorder, 0, postorder.length-1); } private TreeNo...
阅读全文
摘要:class Solution { public List> zigzagLevelOrder(TreeNode root) { List> res=new ArrayList>(); if(root==null) return res; Queue queue=new LinkedList(); Li...
阅读全文
摘要:class Solution { public List> levelOrder(TreeNode root) { List> res=new ArrayList>(); if(root==null) return res; Queue queue=new LinkedList(); queue.ad...
阅读全文
摘要:class Solution { public void recoverTree(TreeNode root) { TreeNode cur=root,pre=null,node1=null,node2=null, p=null; while(cur!=null) { if(cur.left!=null) ...
阅读全文
摘要:public class Solution { public boolean isValidBST(TreeNode root) { Stack stack=new Stack(); TreeNode cur=null; while(root!=null||!stack.isEmpty()) { ...
阅读全文
摘要:public class Solution { public List inorderTraversal(TreeNode root) { List res=new ArrayList(); Stack stack=new Stack(); while(root!=null||!stack.isEmpty()) { ...
阅读全文

浙公网安备 33010602011771号