Skip to content

Instantly share code, notes, and snippets.

@Kishy-nivas
Created June 20, 2018 08:35
Show Gist options
  • Save Kishy-nivas/5302918f5783d22e4b1cb928c26e0e8a to your computer and use it in GitHub Desktop.
Save Kishy-nivas/5302918f5783d22e4b1cb928c26e0e8a 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 == nullptr)
return 0;
return 1 + 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