Skip to content

Commit c746ca4

Browse files
committed
0104-maximum-depth-of-binary-tree
1 parent 1c8753b commit c746ca4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* [ํ’€์ด ๊ฐœ์š”]
3+
* - ์‹œ๊ฐ„๋ณต์žก๋„ : O(n) : ํŠธ๋ฆฌ์˜ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•ด์•ผ ํ•จ
4+
* - ๊ณต๊ฐ„๋ณต์žก๋„ : O(h) : ์žฌ๊ท€์˜ ์ฝœ ์Šคํƒ์€ ํŠธ๋ฆฌ์˜ ๋†’์ด(h) ๋งŒํผ ์Œ“์ž„
5+
*/
6+
class Solution {
7+
/**
8+
* [๋ฌธ์ œ ํ’€์ด ์•„์ด๋””์–ด]
9+
* - ์ด์ง„ ํŠธ๋ฆฌ์˜ ์ตœ๋Œ€ ๋ ˆ๋ฒจ์„ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ
10+
* - ๋ฃจํŠธ๋งŒ ์กด์žฌํ•ด๋„ ๋ ˆ๋ฒจ์€ 1์•”.
11+
* - ์ž์‹ ๋…ธ๋“œ๋ฅผ ์žฌ๊ท€์ ์œผ๋กœ ์กฐํšŒํ•˜๋ฉด์„œ ๋ ˆ๋ฒจ์„ 1์”ฉ ๋Š˜๋ฆฌ๊ณ , ์ตœ๋Œ€๊ฐ’์„ ๊ฐฑ์‹ ํ•˜๋ฏ€๋กœ ํŽธํ–ฅ ํŠธ๋ฆฌ๋ผ๋„ ์ตœ๋Œ€๊ฐ’์œผ๋กœ ๊ฐฑ์‹ ๋จ.
12+
*/
13+
public int maxDepth(TreeNode root) {
14+
if(root == null) return 0;
15+
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
16+
}
17+
}

0 commit comments

Comments
ย (0)