Share my python answer


  • 0
    T

    class Solution:
    # @param {TreeNode} root
    # @return {integer}
    def minDepth(self, root):
    if root is None:
    return 0
    if root.left is None and root.right is None:
    return 1
    else:
    leftDepth = 1 + self.minDepth(root.left)
    rightDepth = 1 + self.minDepth(root.right)
    if leftDepth == 1:
    return rightDepth
    elif rightDepth == 1:
    return leftDepth
    else:
    return min(leftDepth,rightDepth)


  • 0
    C

    Hello, you should learn a little bit about how to arrange the code beautifully~~~


Log in to reply
 

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