二叉树的深度 python
# -*- coding:utf-8 -*-# class TreeNode:#def __init__(self, x):#self.val = x#self.left = None#self.right = Noneclass Solution:def TreeDepth(self, pRoot):...
·
# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def TreeDepth(self, pRoot):
# write code here
self.depthinit()
if not pRoot:
return 0
self.depth +=1
self.depth += max(self.TreeDepth(pRoot.left),self.TreeDepth(pRoot.right))
return self.depth
def depthinit(self):
self.depth = 0
更多推荐
已为社区贡献1条内容
所有评论(0)