File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
maximum-depth-of-binary-tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // 104. Maximum Depth of Binary Tree
3
+ // https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
4
+ // Dale-Study
5
+ //
6
+ // Created by WhiteHyun on 2024/05/12.
7
+ //
8
+
9
+ /**
10
+ * Definition for a binary tree node.
11
+ * public class TreeNode {
12
+ * public var val: Int
13
+ * public var left: TreeNode?
14
+ * public var right: TreeNode?
15
+ * public init() { self.val = 0; self.left = nil; self.right = nil; }
16
+ * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }
17
+ * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {
18
+ * self.val = val
19
+ * self.left = left
20
+ * self.right = right
21
+ * }
22
+ * }
23
+ */
24
+ final class Solution {
25
+ func maxDepth( _ node: TreeNode ? ) -> Int {
26
+ guard let node else { return 0 }
27
+
28
+ return max ( maxDepth ( node. left) , maxDepth ( node. right) ) + 1
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments