[codility]tree_height
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的更多相关文章
- Codility NumberSolitaire Solution
1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...
- codility flags solution
How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...
- GenomicRangeQuery /codility/ preFix sums
首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...
- *[codility]Peaks
https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...
- *[codility]Country network
https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...
- *[codility]AscendingPaths
https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...
- *[codility]MaxDoubleSliceSum
https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...
- *[codility]Fish
https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...
- *[codility]CartesianSequence
https://codility.com/programmers/challenges/upsilon2012 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...
随机推荐
- ibatis 到 MyBatis区别
http://blog.csdn.net/techbirds_bao/article/details/9235309 简介: 本文主要讲述了 iBatis 2.x 和 MyBatis 3.0.x 的区 ...
- VBA文件处理
Option Explicit ' ▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽ ' Excel对象 ' △△△△△△△△△△△△△△△△△△ ' Open Public Function FileOpen_ ...
- jQuery Table2CSV插件(表格转CSV) 完美支持colspan和rowspan
table2csv:将表格转化为csv数据 参数:一个JSON对象 { 'repeatChar':'拆分单元格填充字符', //默认为null则将单元格值填充到拆分的每个单元格中,如果给定字符串则用给 ...
- asp:时间的显示
DateTime dt = DateTime.Now;// Label1.Text = dt.ToString();//2005-11-5 13:21:25// Label2.Text = ...
- 事件兼容IE
addEvent:function(target, functionref, tasktype) { if (target.addEventListener) target.addEventListe ...
- javascript检测是否安装了flash
检测是否安装了flash function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版 ...
- JQ方法大全
Dom:Attribute:$("p").addClass(css中定义的样式类型); 给某个元素添加样式$("img").attr({src:"te ...
- [PHP]MemCached高级缓存
Memcache Win32 的安装下载:Memcache Win32 [www.php100.com] [www.jehiah.cz/projects/memcached-win32/] 1.解 ...
- 走进WCF一 (异常如此多娇,引无数码农竞折煞)
对于WCF一直都是只知其然,公司框架的架构者也只是对我们授之以鱼,而不授之以渔. 带着初学者的态度进入了大神Artech的博客,逐步慢慢上手. 我的解决方案(和大神的一模一样,只是过程中一波三折的) ...
- python3 中自带urllib库可下载图片到本地
刚从python3下载图片的语句python2的不太一样,具体python3语句如下: form urllib import request jpg_link = '......' #图片链接 re ...