Created
April 13, 2017 15:20
-
-
Save s4553711/4c11202902f2e9bf871635b85edab4cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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 == NULL) return 0; | |
int levl = maxDepth(root->left); | |
int revl = maxDepth(root->right); | |
return (revl > levl ? revl : levl) + 1; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment