Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0271d99

Browse files
Create 559.py
1 parent 526cf4d commit 0271d99

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎501-1000/559.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
# Definition for a Node.
3+
class Node:
4+
def __init__(self, val=None, children=None):
5+
self.val = val
6+
self.children = children
7+
"""
8+
9+
class Solution:
10+
def maxDepth(self, root: 'Node') -> int:
11+
if not root:
12+
return 0
13+
d = 1
14+
if root.children:
15+
d += max(self.maxDepth(child) for child in root.children)
16+
return d
17+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /