104. Maximum Depth of Binary Tree
-
104. Maximum Depth of Binary TreeProgramming/leetcode 2021. 3. 17. 10:00
public int maxDepth(TreeNode root) { if (root == null) return 0; if (root.left == null && root.right == null) return 1; if (root.left != null && root.right == null) return maxDepth(root.left) + 1; if (root.left == null && root.right != null) return maxDepth(root.right) + 1; return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; } 풀이 방법은 여러 가지가 있겠다. BFS, 재귀... 먼저 BFS로 푼 것이다. Queue에 넣고 해당..