Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.05 KB

_559. Maximum Depth of N-ary Tree.md

File metadata and controls

44 lines (32 loc) · 1.05 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : September 24, 2024

Last updated : September 24, 2024


Related Topics : Tree, Depth-First Search, Breadth-First Search

Acceptance Rate : 72.6 %


Solutions

Python

"""
# Definition for a Node.
class Node:
    def __init__(self, val: Optional[int] = None, children: Optional[List['Node']] = None):
        self.val = val
        self.children = children
"""

class Solution:
    def maxDepth(self, root: 'Node') -> int:
        if not root :
            return 0
        if not root.children :
            return 1
        return max(self.maxDepth(x) for x in root.children) + 1