欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

leetcode--minimum-depth-of-binary-tree

程序员文章站 2024-02-29 12:04:58
...

minimum-depth-of-binary-tree
leetcode--minimum-depth-of-binary-tree
参考答案,但是没能通过。。。

# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

#
# 
# @param root TreeNode类 
# @return int整型
#
class Solution:
    def run(self , root ):
        # write code here
        if not root:
            return 0
        if not root.left and root.right:
            return self.run(root.right) + 1
        if root.left and not root.right:
            return self.run(root.left) + 1
        return min(self.run(root.left), self.run(root.right)) + 1
        
相关标签: Leetcode