码迷,mamicode.com
首页 > 编程语言 > 详细

leetcode559 Python3 128ms N叉树的最大深度

时间:2018-07-28 11:54:17      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:def   not   pre   val   return   code   elf   init   tco   

"""
# Definition for a Node.
class Node(object):
    def __init__(self, val, children):
        self.val = val
        self.children = children
"""
class Solution(object):
    def maxDepth(self, root):
        """
        :type root: Node
        :rtype: int
        """
        if not root:
            return 0
        if not root.children:
            return 1
        return 1 + max(list(map(self.maxDepth, root.children)))
        

leetcode559 Python3 128ms N叉树的最大深度

标签:def   not   pre   val   return   code   elf   init   tco   

原文地址:https://www.cnblogs.com/theodoric008/p/9380391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!