/**
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* class TreeNode(var `val`: Int) {
* var left: TreeNode? = null
* var right: TreeNode? = null
* }
*/
class Solution {
fun maxDepth(root: TreeNode?): Int {
if (root == null) {
return 0
}
return Math.max(maxDepth(root?.left), maxDepth(root?.right)) + 1
}
}
'알고리즘 > Leetcode' 카테고리의 다른 글
[leetcode/python3] 1768.Merge Strings Alternately (0) | 2021.04.10 |
---|---|
[leetcode/kotlin] 575.Distribute Candies (0) | 2021.03.16 |
[leetcode/kotlin] 1492. The kth Factor of n (0) | 2020.12.05 |
[leetcode/kotlin] 1446. Consecutive Characters (0) | 2020.11.03 |
[leetcode/kotlin] 938. Range Sum of BST (0) | 2020.10.15 |