#-*- coding: UTF-8 -*-
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def maxDepth(self, root):
if root==None:return 0
leftDepth=self.maxDepth(root.left)
rightDepth=self.maxDepth(root.right)
return leftDepth+1 if leftDepth >rightDepth else (rightDepth+1)
相关文章
- Construct Binary Tree from Preorder and Inorder Traversal leetcode java
- Leetcode: Convert sorted list to binary search tree (No. 109)
- [LeetCode] Balanced Binary Tree 深度搜索
- leetcode 108 Convert Sorted Array to Binary Search Tree ----- java
- 【LeetCode】108. Convert Sorted Array to Binary Search Tree 解题报告 (Java & Python)
- [LeetCode]Binary Tree Level Order Traversal
- [LeetCode]Maximum Depth of Binary Tree
- [LeetCode]Balanced Binary Tree
- 【Binary Tree Maximum Path Sum】cpp
- [Leetcode][JAVA] Convert Sorted Array to Binary Search Tree && Convert Sorted List to Binary Search Tree