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 ...
随机推荐
- C# 将数字时间转化为特定格式字符串
在工作中,经常遇到,将距离某点的时间段转化为"HH:MM:SS"格式时间的情况. 经过总结,用C#实现了一个特别好的办法: DateTime _dTNow = DateTime. ...
- FunsionCharts图标控件点击
1.点击执行js 在页面中添加点击chart后需要触发的js事件: <script> functionmyJS(myVar){ window.alert(m ...
- delphi XE 5 Android 真机调试简易安装教程
① FireMonkey[DELPHI XE5]QQ群号:165232328,群内超过1600移动开发爱好者 第一步,打开手机中的USB调试 电脑自动装驱动,但是找不到 去手机官网下载驱动 手动安装驱 ...
- 移动APP项目优化
团队计划:设计一款给用户提供就医帮助的安卓APP. 项目计划:两个月内团队成员共同开发完成此款APP,此款APP提供预约挂号,名医名院咨询,就医导航等功能. 角色职责:负责交互设计.UI界面设计.1. ...
- Hibernate之环境搭建及demo
ORM概念 ORM即Object/Relation Mapping, 对象/关系数据库映射.ORM是一种规范,完成面向对象编程语言到关系数据库之间的映射.J2EE中的JPA就是一种ORM规范. ORM ...
- flume+sparkStreaming实例 实时监控文件demo
1,flume所在的节点不和spark同一个集群 v50和 10-15节点 flume在v50里面 flume-agent.conf spark是开的work节点,就是单点计算节点,不涉及到mast ...
- async和await
总结下博客园中看到的async和await public static class TaskAsyncHelper { /// <summary> /// 将一个方法function异步运 ...
- 如何运用CSS写小三角
<html> <div class="con"></div> </html> <style> .con{width:0; ...
- 深入了解try catch
@Test public void testWeiXin(){ System.out.println(task()); } private boolean task(){ try { int i = ...
- Learn GIT
1.创建版本库: git init 设置用户: git config --global user.email "you@example.com" 2.添加到仓库(将修改的内容提交到 ...