摘要: 经典题,黄亮讲过。java版就会难看一点,要写个wrapper class,把结果放在一起。 这里要return三个变量,如果只返回两个变量(node 和 isAncestor),实现起来的逻辑会复杂一些。class Solution { class Result{ TreeNo... 阅读全文
posted @ 2015-02-26 12:47 江南第一少 阅读(188) 评论(0) 推荐(0)
摘要: Assume you know the parent of the node, return the inorder successor. 1 class Solution { 2 public TreeNode inorderSuccessor(TreeNode node) { 3 i... 阅读全文
posted @ 2015-02-26 11:53 江南第一少 阅读(173) 评论(0) 推荐(0)
摘要: 1 public class Solution { 2 public boolean isBalanced(TreeNode root) { 3 int result = checkHeight(root); 4 return result != -1; 5... 阅读全文
posted @ 2015-02-26 09:35 江南第一少 阅读(110) 评论(0) 推荐(0)
摘要: 可以使用一个extra的stack。 1 class Solution { 2 public Stack sortStack(Stack s1) { 3 Stack s2 = new Stack(); 4 while(!s1.isEmpty()) { 5 ... 阅读全文
posted @ 2015-02-26 09:27 江南第一少 阅读(143) 评论(0) 推荐(0)