2018年5月9日

面试39---二叉树的深度

摘要: 题目链接 求解二叉树的深度,延伸可见leetcode110题。 法一:dfs。 1 private int TreeDepth(TreeNode root) { 2 if(root == null) { 3 return 0; 4 } 5 int l = TreeDepth(root.left); 阅读全文

posted @ 2018-05-09 11:47 二十年后20 阅读(73) 评论(0) 推荐(0) 编辑

110.Balanced Binary Tree---《剑指offer》面试39

摘要: 题目链接 题目大意:判断一个二叉树是否是平衡二叉树。 法一:dfs。利用求解二叉树的高度延伸,先计算左子树的高度,再计算右子树的高度,然后两者进行比较。o(nlgn)。代码如下(耗时4ms): 1 public boolean isBalanced(TreeNode root) { 2 if(roo 阅读全文

posted @ 2018-05-09 11:43 二十年后20 阅读(91) 评论(0) 推荐(0) 编辑

导航