Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- database
- implement
- Stack
- 구현
- Counting
- 자바
- greedy
- Data Structure
- 코딩테스트
- SQL
- bit manipulation
- Method
- Binary Tree
- geometry
- 파이썬
- two pointers
- Class
- simulation
- dynamic programming
- Binary Search
- array
- Number Theory
- Math
- Tree
- hash table
- sorting
- string
- Matrix
- java
- 코테
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 104. Maximum Depth of Binary Tree 본문
1. Input
1) TreeNode root
2. Output
1) 이진 트리의 최대 깊이를 반환
3. Constraint
1) 트리의 노드 수의 범위는 [0, 104]
2) -100 <= Node.val <= 100
4. Example
Input: root = [3,9,20,null,null,15,7] -> Output: 3
설명: 3-20-7 또는 3-20-15일 때 깊이가 3으로 가장 깊다.
5. Code
1) 첫 코드(2023/01/17)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
int answer;
if(root==null)
answer = 0;
else
answer = 1 + Math.max(maxDepth(root.right), maxDepth(root.left));
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Medium] 137. Single Number II (0) | 2023.01.19 |
---|---|
[프로그래머스/Lv.2] 스킬트리 (0) | 2023.01.17 |
[LeetCode/Easy] 2351. First Letter to Appear Twice (0) | 2023.01.16 |
[LeetCode/Easy] 2347. Best Poker Hand (0) | 2023.01.16 |
[LeetCode/Easy] 2341. Maximum Number of Pairs in Array (0) | 2023.01.16 |