leetcode--minimum-depth-of-binary-tree
程序员文章站
2024-02-29 12:04:58
...
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
下一篇: JavaWeb之DBUtils