Swift 3.1 solution using extension


  • 0
    S
    class Solution {
    	func maxDepth(_ root: TreeNode?) -> Int {
    		return root?.maxDepth ?? 0
    	}
    }
    
    extension TreeNode {
    	var maxDepth: Int {
    		return max(left?.maxDepth ?? 0, right?.maxDepth ?? 0) + 1
    	}
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.