'''
https://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73?tpId=196&&tqId=37055&rp=1&ru=/activity/oj&qru=/ta/job-code-total/question-ranking
'''
# -*- coding:utf-8 -*-
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
# @param root TreeNode类
# @return int整型
#
class Solution:
def maxDepth(self , root ):
# write code here
if not root:
return 0
out = []
def dfs(root,res):
if not root:
return
if not root.left and not root.right:
out.append(res)
if root.left:
dfs(root.left, res+[root.left.val])
if root.right:
dfs(root.right, res+[root.right.val])
dfs(root,[root.val])
depth = 0
for i in out:
if len(i)>depth:
depth = len(i)
return depth