二叉树的深度 python

# -*- 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

猜你喜欢

转载自blog.csdn.net/qq_41359265/article/details/84203311
今日推荐