File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,31 @@ public class Solution {
218
218
}
219
219
```
220
220
221
+ #### Swift
222
+
223
+ ``` swift
224
+ /* public class TreeNode {
225
+ * public var val: Int
226
+ * public var left: TreeNode?
227
+ * public var right: TreeNode?
228
+ * public init(_ val: Int) {
229
+ * self.val = val
230
+ * self.left = nil
231
+ * self.right = nil
232
+ * }
233
+ * }
234
+ */
235
+
236
+ class Solution {
237
+ func maxDepth (_ root : TreeNode? ) -> Int {
238
+ guard let root = root else {
239
+ return 0
240
+ }
241
+ return 1 + max (maxDepth (root.left ), maxDepth (root.right ))
242
+ }
243
+ }
244
+ ```
245
+
221
246
<!-- tabs: end -->
222
247
223
248
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ /* public class TreeNode {
2
+ * public var val: Int
3
+ * public var left: TreeNode?
4
+ * public var right: TreeNode?
5
+ * public init(_ val: Int) {
6
+ * self.val = val
7
+ * self.left = nil
8
+ * self.right = nil
9
+ * }
10
+ * }
11
+ */
12
+
13
+ class Solution {
14
+ func maxDepth( _ root: TreeNode ? ) -> Int {
15
+ guard let root = root else {
16
+ return 0
17
+ }
18
+ return 1 + max( maxDepth ( root. left) , maxDepth ( root. right) )
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments