面试题55:二叉树的深度(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
        if pRoot==None:return 0
        left=self.TreeDepth(pRoot.left)+1
        right=self.TreeDepth(pRoot.right)+1
        return left if left>right else right

 

你可能感兴趣的:(面试题55:二叉树的深度(Python))