Leetcode-Solutions

My Leetcode Solutions.

View on GitHub

104. Maximum Depth of Binary Tree

Topics: Tree Depth-First Search Breadth-First Search Binary Tree

Solution

Implementation

class Solution {
    fun maxDepth(root: TreeNode?): Int {
        if (root == null) return 0
        return 1 + max(maxDepth(root.left), maxDepth(root.right))
    }
}