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

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐