-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
31 lines (26 loc) · 727 Bytes
/
solution.py
File metadata and controls
31 lines (26 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
# 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
"""
max_depth = 0
stack = []
next_stack = []
if root: stack.append(root)
while len(stack) > 0:
node = stack.pop()
if len(node.children) > 0:
next_stack += node.children
if len(stack) == 0:
max_depth += 1
stack = next_stack
next_stack = []
return max_depth