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);
}