[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 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...
随机推荐
- Python(2.7.6) 迭代器
除了对列表.集合和字典等进行迭代,还能对其他对象进行迭代:实现 __iter__ 方法的对象.例如, 文件对象就是可迭代的: >>> dir(file) ['__class__', ...
- 对list集合中的对象进行排序(转载)
原文链接:http://blog.csdn.net/veryisjava/article/details/51675036 Collections对List集合中的数据进行排序 有时候需要对集合中的元 ...
- How Indexes Are Stored
reference: http://docs.oracle.com/cd/B28359_01/server.111/b28318/schema.htm#CHDJGADJ 当创建索引的时候,Oracl ...
- PHP JQuery Json
PHP: echo Json_encode($result); Jquery: $.get( 'process.php', {'p1':'aa','p2':'dd', 'data_type':'jso ...
- ajax.abort 终止AJAX请求
$(document).ready(function () { var ajax; $('#choice').change(function() ...
- 层叠上下文 Stacking Context
层叠上下文 Stacking Context 在CSS2.1规范中,每个盒模型的位置是三维的,分别是平面画布上的x轴,y轴以及表示层叠的z轴.对于每个html元素,都可以通过设置z-index属性来设 ...
- OpenJudge/Poj 2001 Shortest Prefixes
1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...
- svn 项目转移
http://www.cnblogs.com/techMichaelLee/p/3193197.html (参考) svnadmin dump /home/svn/project > /home ...
- DevTools:Chrome 内置调试工具
DevTools:Chrome 内置调试工具 2016-08-29 https://developers.google.com/web/tools/chrome-devtools
- Linux简介及Ubuntu安装
Linux简介及Ubuntu安装 常见指令 系统管理命令 打包压缩相关命令 关机/重启机器 Linux管道 Linux软件包管理 vim使用 用户及用户组管理 文件权限管理 大牛笔记-www.weix ...