Codility Tree Height
public class HeightOfTreeSolution {
static int height=-1;
public int solution(Tree T) {
// write your code in Java SE 8
if (T == null) return height;
height = heightOfTree(T);
return height;
}
public int heightOfTree(Tree node){
if (node!=null) {
if (node.l==null) {
return 1+heightOfTree(node.r);
}
if (node.r==null) {
return 1+heightOfTree(node.l);
}
else{
return 1+Math.max(heightOfTree(node.r),heightOfTree(node.l));
}
}
return 0;
}
}
问题描述:
Write a function:
class Solution { public int solution(Tree T); }
that, given a non-empty binary tree T consisting of N nodes, returns its height. For example, given tree T shown in the figure above, the function should return 2, as explained above. Note that the values contained in the nodes are not relevant in this task.
Codility Tree Height的更多相关文章
- LeetCode Binary Tree Upside Down
原题链接在这里:https://leetcode.com/problems/binary-tree-upside-down/ Given a binary tree where all the rig ...
- 【Egret】中tree组件使用案例
Egret中tree组件使用案例,包含(文本过多时,自动换行功能) 下面代码结合http://bbs.egret.com/forum.php?mod=viewthread&tid=19028& ...
- BST 解析 (二)height and deletion
前面一章介绍了BST的结构和一些简单的基本功能,例如:insert,findMin,nextLarger等等.这一节主要讲解一些BST的delete node操作还有BST的height的分析以及一些 ...
- AVL Tree Insertion
Overview AVL tree is a special binary search tree, by definition, any node, its left tree height and ...
- B+ Tree vs B Trees
原文地址:https://blog.csdn.net/dashuniuniu/article/details/51072795 引子 最近一直回顾自己曾经写的一些文档,有一篇是关于 Clang Rew ...
- LeetCode 655. Print Binary Tree (C++)
题目: Print a binary tree in an m*n 2D string array following these rules: The row number m should be ...
- LeetCode Construct Binary Tree from String
原题链接在这里:https://leetcode.com/problems/construct-binary-tree-from-string/description/ 题目: You need to ...
- Red–black tree ---reference wiki
source address:http://en.wikipedia.org/wiki/Red%E2%80%93black_tree A red–black tree is a type of sel ...
- leetCode笔记--binary tree
993. Cousins in Binary Tree In a binary tree, the root node is at depth 0, and children of each dept ...
随机推荐
- ClientScript.RegisterStartupScript 不起作用
asp.net webform 使用 ClientScript.RegisterStartupScript 不起作用 form 加上 runat="server",ok
- MySQL字段类型详解
MySQL支持大量的列类型,它可以被分为3类:数字类型.日期和时间类型以及字符串(字符)类型.本节首先给出可用类型的一个概述,并且总结每个列类型的存储需求,然后提供每个类中的类型性质的更详细的描述. ...
- JAVA可阻塞队列-ArrayBlockingQueue子类BlockingQueue的应用,使用它来实现子线程打印10次,主线程打印100次,如此反复
/** * 使用BlockingQueue实现主子线程互相打印 * @author duwenlei * */ public class BlockingQueueTest { public stat ...
- mysql 批量导出建表语句 (视图,函数同理)
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream;import ja ...
- Linux系统结构
Linux系统一般有4个主要部分: 内核.shell.文件系统和应用程序.内核.shell和文件系统一起形成了基本的操作系统结构,它们使得用户可以运行程序.管理文件并使用系统.部分层次结构如图 ...
- ImageLoader图片加载
http://blog.csdn.net/liu1164316159/article/details/38728259 转载请注明http://write.blog.csdn.net/po ...
- bean找不到异常
和这种的 原因: 这些都是因为bean注入的时候没有找个要注入的bean 解决办法: 1.查看dubbo文件中,暴露接口是否引入bean 2.如果有引入,查看引入路径和类是否存在.
- 部署wcf到IIS时的问题
1,部署到IIS后,在浏览器可以访问.但客户端添加服务引用时,出现错误: - 下载“http://admin-pc/IISHostService/Service1.svc?xsd=xsd0”时出错.- ...
- &和&&
int j = 5,k = 3; if(!(j==k) && (j == 1 + k++ )) { } System.out.println(j); System.out.printl ...
- VS.Net 2015 Update3 学习(1) 支持Webpack
让vs.net 编译的时候自动执行webpack 首先 管理员模式下打开 “Developer Command Prompt for VS2015", 是管理员模式啊! 然后进入 cd c: ...