Skip to content

Commit b809b98

Browse files
committed
Maximum depth of binary tree
1 parent 7ee873d commit b809b98

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# μ—°κ΄€ 링크
2+
- [문제 풀이 μŠ€μΌ€μ€„](https://github.com/orgs/DaleStudy/projects/6/views/5)
3+
- [λ‹΅μ•ˆ μ½”λ“œ μ œμΆœλ²•](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C)
4+
5+
# Problem
6+
- 문제 링크 : https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
7+
- 문제 이름 : Maximum Depth of Binary Tree
8+
- 문제 번호 : 104
9+
- λ‚œμ΄λ„ : easy
10+
- μΉ΄ν…Œκ³ λ¦¬ :
11+
12+
# 문제 μ„€λͺ…
13+
14+
15+
# 아이디어
16+
- μž¬κ·€
17+
18+
# βœ… μ½”λ“œ (Solution)
19+
20+
```cpp
21+
/**
22+
* Definition for a binary tree node.
23+
* struct TreeNode {
24+
* int val;
25+
* TreeNode *left;
26+
* TreeNode *right;
27+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
28+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
29+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
30+
* };
31+
*/
32+
class Solution {
33+
public:
34+
int maxDepth(TreeNode* root) {
35+
if(!root)
36+
return 0;
37+
return 1 + max(maxDepth(root->left), maxDepth(root->right));
38+
}
39+
};
40+
```
41+
42+
43+
# πŸ” μ½”λ“œ μ„€λͺ…
44+
45+
46+
# μ΅œμ ν™” 포인트 (Optimality Discussion)
47+
β€’ μ΅œμ ν™”ν•œ μ΄μœ μ™€ 원리
48+
β€’ 더 쀄일 수 μžˆλŠ” μ—¬μ§€λŠ” μžˆλŠ”κ°€?
49+
β€’ κΈ°μ‘΄ 방법 λŒ€λΉ„ μ–Όλ§ˆλ‚˜ νš¨μœ¨μ μ΄μ—ˆλŠ”μ§€
50+
51+
# πŸ§ͺ ν…ŒμŠ€νŠΈ & μ—£μ§€ μΌ€μ΄μŠ€
52+
53+
# πŸ“š κ΄€λ ¨ 지식 볡슡
54+
55+
# πŸ” 회고
56+
57+

0 commit comments

Comments
Β (0)