剑指offer55题目一

#include<iostream>
#include<algorithm>
using namespace std;

struct TreeNode {
	TreeNode* l;
	TreeNode* r;
	int value;
};

int depth(TreeNode *t,int h) {
	if (t == NULL) return h;
	else return max(depth(t->l,h+1), depth(t->r, h+1));
}

int main() {
	TreeNode *t = new TreeNode();
	t->value = 1;
	t->l = new TreeNode(); t->l->value = 2;
	t->r = new TreeNode(); t->r->value = 3;
	t->r->r = new TreeNode(); t->r->r->value = 4;
	t->l->l = new TreeNode(); t->l->l->value = 5;
	t->l->r = new TreeNode(); t->l->r->value = 7;
	t->l->r->l = new TreeNode(); t->l->r->l->value = 6;
	cout << depth(t,0) << endl;
	return 0;
}

阅读更多
个人分类: 剑指offer
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭