Oneline Python


  • 0
    W
    class Solution(object):
        def maxDepth(self, root, i = 0):
            return 0 if root == None else max(self.maxDepth(root.left),self.maxDepth(root.right)) + 1
    

    Another way of writing this:

    class Solution(object):
        def maxDepth(self, root):
            return self.maxd(root,0)
        
        def maxd(self, root, i = 0):
            if root == None:
                return i
            else:
                i += 1
                return max(self.maxd(root.left,i),self.maxd(root.right,i))
    

Log in to reply
 

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