97.二叉樹的最大深度
阿新 • • 發佈:2018-09-14
root pub 二叉樹 http depth blog src com cnblogs
轉自[LeetCode] Maximum Depth of Binary Tree 二叉樹的最大深度
/** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right = NULL; * } * } */ class Solution { public: /** * @param root: The root of binary tree. * @return: An integer */ int maxDepth(TreeNode * root) { if (!root) return 0; return 1 + max(maxDepth(root->left), maxDepth(root->right)); } };
97.二叉樹的最大深度