Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created April 13, 2017 15:20
Show Gist options
  • Save s4553711/4c11202902f2e9bf871635b85edab4cf to your computer and use it in GitHub Desktop.
Save s4553711/4c11202902f2e9bf871635b85edab4cf to your computer and use it in GitHub Desktop.
/**
* 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