[LeetCode] 104. Maximum Depth of Binary Tree(Kotlin)

0

LeetCode

목록 보기
10/58
post-thumbnail
post-custom-banner

[LeetCode] 104. Maximum Depth of Binary Tree(Kotlin)

풀이

/**
 * 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
 * }
 */

import kotlin.math.*

class Solution {
    fun maxDepth(root: TreeNode?): Int {
        if(root == null) return 0
        
        var result = 1 + max(maxDepth(root.left), maxDepth(root.right))
        return result
    }
}
profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글