标签:struct min getheight 使用 nod return == style max
1 /* 2 struct TreeNode { 3 int val; 4 struct TreeNode *left; 5 struct TreeNode *right; 6 TreeNode(int x) : 7 val(x), left(NULL), right(NULL) { 8 } 9 };*/ 10 class Solution { 11 public: 12 int TreeDepth(TreeNode* pRoot) 13 { 14 return getHeight(pRoot); 15 } 16 int getHeight(TreeNode *r) { 17 if (r == NULL) 18 return 0; 19 return max(getHeight(r->left), getHeight(r->right))+1; 20 } 21 };
Notes: algorithm头文件下的常用函数max(),min(),abs()
#include<algorithm>
using namespace std; //头文件下加这一行,方能正常使用
标签:struct min getheight 使用 nod return == style max
原文地址:https://www.cnblogs.com/lettleshel/p/10029028.html