Skip to content

Commit

Permalink
이슈 #112에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 17, 2024
1 parent 505f3db commit 701c3cc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LeetCode/Maximum_Depth_of_Binary_Tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode* root) {
if (root == nullptr) {
return 0;
}

int leftDepth = maxDepth(root->left);
int rightDepth = maxDepth(root->right);

return max(leftDepth, rightDepth) + 1;
}
};

0 comments on commit 701c3cc

Please sign in to comment.