#include<stdio.h> #include<string.h> #include <pthread.h> #include <iostream> #include <algorithm> #include <vector> #include <stack> #include <stdlib.h> #include <sstream> using namespace std; struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; class Solution { public: int TreeDepth(TreeNode* pRoot) { if(!pRoot) return 0; return max(1+TreeDepth(pRoot->left),1+TreeDepth(pRoot->right)); } }; int main() { TreeNode*t1=new TreeNode(6); TreeNode*t2=new TreeNode(7); TreeNode*t3=new TreeNode(8); TreeNode*t4=new TreeNode(9); TreeNode*t5=new TreeNode(10); TreeNode*t6=new TreeNode(11); t1->left=t2; t1->right=t3; t2->left=t4; t2->right=t5; t4->left=t6; Solution s; cout<<s.TreeDepth(t1); return 0; }