摘要:
超简洁的代码本来考虑是不是真的要每个点求一个maxDepth,看来是的哟public class Solution { public boolean isBalanced(TreeNode root) { if (root==null) return true; i... 阅读全文
摘要:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题解完全抄自ref的说明,感谢!“题解:先复习下什么是二叉搜索树(引自Wikipedia):二叉查找树(B... 阅读全文
摘要:
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
摘要:
跟之前的解法一模一样Binary Tree Level Order Traversal I,II 不赘述public class Solution { public ArrayList> zigzagLevelOrder(TreeNode root) { ArrayList> r... 阅读全文
摘要:
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
摘要:
有个问题,就是不能和same tree一样光看root 做recursive而是必须比较左右节点,因为对称是指整个树否则就会出现 1 2 2 # 3 3public class Solution { public boolean isSymmetric(TreeNode root) { ... 阅读全文
摘要:
简单题ref“使用的是先序遍历,算法的复杂度跟遍历是一致的,如果使用递归,时间复杂度是O(n),空间复杂度是O(logn)。” by codegankerhttp://blog.csdn.net/linhuanmars/article/details/22839819•Time to search ... 阅读全文
摘要:
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ... 阅读全文
摘要:
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文
摘要:
Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="... 阅读全文