标签:pytho 节点 class 二叉树的深度 val return init tree pre
思路:用递归思想,不停往下找节点,找到一个节点加1
# -*- 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
if pRoot == None:
return 0
left = self.TreeDepth(pRoot.left)
right = self.TreeDepth(pRoot.right)
return max(left, right) + 1
标签:pytho 节点 class 二叉树的深度 val return init tree pre
原文地址:https://www.cnblogs.com/dolisun/p/11330804.html