Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 상가수익률계산기
- 알고리즘풀기
- 릿코드풀기
- 파이썬 알고리즘
- 알고리즘풀이
- 파이썬 프로그래머스
- 파이썬알고리즘
- binary search
- 릿코드 풀기
- leetcode 풀기
- python priority queue
- python 알고리즘
- 파이썬 알고리즘 풀기
- 릿코드 파이썬
- 릿코드풀이
- 코틀린기초
- LeetCode
- leetcode풀기
- python sorted
- python zip_longest
- 파이썬릿코드풀기
- 파이썬릿코드
- 릿코드
- python 릿코드
- python xor
- 파이썬알고리즘풀기
- python Leetcode
- 파이썬 릿코드
- 잇츠디모
- leetcode풀이
Archives
- Today
- Total
소프트웨어에 대한 모든 것
LeetCode 풀기 - 559. Maximum Depth of N-ary Tree 본문
반응형
559. Maximum Depth of N-ary Tree
https://leetcode.com/problems/maximum-depth-of-n-ary-tree/
Maximum Depth of N-ary Tree - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제)


솔루션1) recursive
"""
# Definition for a Node.
class Node:
def __init__(self, val=None, children=None):
self.val = val
self.children = children
"""
class Solution:
def maxDepth(self, root: 'Node', depth=0) -> int:
if root is None: return depth
depth += 1
cur_depth = depth
for child in root.children:
depth = max(depth, self.maxDepth(child, cur_depth))
return depth
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
| LeetCode 풀기 - 997. Find the Town Judge (0) | 2022.01.04 |
|---|---|
| LeetCode 풀기 - 1026. Maximum Difference Between Node and Ancestor (0) | 2021.12.31 |
| LeetCode 풀기 - 1356. Sort Integers by The Number of 1 Bits (0) | 2021.12.29 |
| LeetCode 풀기 - 1380. Lucky Numbers in a Matrix (0) | 2021.12.29 |
| LeetCode 풀기 - 227. Basic Calculator II (0) | 2021.12.28 |
Comments