Commit cc315b06 by “安晓东”

第八次作业-二叉树

parent 44fbd452
# 二叉树的最大深度
# 给定一个二叉树,找出其最大深度。
# 二叉树的深度为根节点到最远叶子节点的距离。
# 如果二叉树为空,则深度为0
# 如果不为空,分别求左子树的深度和右子树的深度,取最大的再加1
class Solution:
def maxDepth(self, root):
if root == None:
return 0
else:
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
# a = [1,3,5,6]
# for i in a:
# s = a.index(i)
# print(str(i)+'====='+str(s))
class Solution(object):
def __init__(self,lis):
self.lis = lis
def deleteNode(self, node):
for i in self.lis:
if i == node:
self.lis.remove(node)
return self.lis
if __name__ == '__main__':
str = [1, 3, 4, 5, 2, 6]
s = Solution(str)
print(s.deleteNode(6))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment