Created
April 11, 2021 08:09
-
-
Save lishunan246/7b9e1d79c5da67cea3efbb43f62d7bf1 to your computer and use it in GitHub Desktop.
剑指 Offer 55 - I. 二叉树的深度
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: | |
int maxDepth(TreeNode* root) { | |
if (root == nullptr) { | |
return 0; | |
} else { | |
return 1 + std::max(maxDepth(root->left), maxDepth(root->right)); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment