http://codility.com/demo/take-sample-test/treeheight

非常非常简单的求树的深度。不忍直视。

// you can also use includes, for example:
// #include <algorithm> int get_height(tree * T) {
if (T->l == NULL && T->r == NULL)
return 0;
int hl = 0;
int hr = 0;
if (T->l != NULL)
hl = get_height(T->l);
if (T->r != NULL)
hr = get_height(T->r);
return max(hl, hr) + 1;
} int solution(tree * T) {
// write your code in C++98
return get_height(T);
}

  

[codility]tree_height的更多相关文章

  1. Codility NumberSolitaire Solution

    1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...

  2. codility flags solution

    How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...

  3. GenomicRangeQuery /codility/ preFix sums

    首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...

  4. *[codility]Peaks

    https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...

  5. *[codility]Country network

    https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...

  6. *[codility]AscendingPaths

    https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...

  7. *[codility]MaxDoubleSliceSum

    https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...

  8. *[codility]Fish

    https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...

  9. *[codility]CartesianSequence

    https://codility.com/programmers/challenges/upsilon2012 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...

随机推荐

  1. java poi出excel换行问题

    POI操作excel实现换行问题. package jp.co.misumi.mdm.batch.common.jobrunner; import java.io.FileInputStream; i ...

  2. HDFS之SequenceFile和MapFile

    http://blog.csdn.net/javaman_chen/article/details/7241087 Hadoop的HDFS和MapReduce子框架主要是针对大数据文件来设计的,在小文 ...

  3. Android的自动对焦

    1,什么是自动对焦? ---安卓的自动对焦的概念是指能够在指定的位置计算出准确的焦点位置. 这个就好像是传统意义上的手动对焦.但是google是这个意思. 2.什么是追焦? ----安卓的追焦是指FO ...

  4. ~/.ssh目录找不到解决方法

    执行 cd ~/.ssh发现ssh目录找不到 [root@ocdp2 ~]# cd ~/.ssh -bash: cd: /root/.ssh: No such file or directory 原因 ...

  5. [转] sql数据类型 varchar与nvarchar的区别

    SQL Server提供两种数据类型来存储字符信息.在如何在SQL Server或应用程序中使用方面,这两种数据类型大致是一样的.差别在于nvarchar是用于存储处理数据库图表中多语言数据的Unic ...

  6. ios Swift 动手写

    Swift语言概览 基本概念 注:这一节的代码源自The Swift Programming Language中的A Swift Tour. Hello, world 类似于脚本语言,下面的代码即是一 ...

  7. Sytem 表空间很大

    SYSTEM表空间使用率达到了99%, 经查出,是审计表AUD$占用绝大部分的空间. -- 占用表空间system对象大小排名 SELECT * MB FROM DBA_SEGMENTS WHERE ...

  8. Xcode中添加代码块的方式

    在写代码的过程中,经常会有重复的代码(比如说,cell的使用),当然了复制粘贴也不是不行,但是Xcode提供了一个很方便的东西. 1.在Xcode右下角你会看到有一个{}的东西,这里是一些常用的代码块 ...

  9. JAVA日历

    效果图如下: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import ...

  10. C++ txt文档读取

    void readfile(string filepath){ ifstream myfile; if (!myfile) { cout << "打开文件出错!"; e ...