일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Decorator
- attribute
- Python Code
- concurrency
- Class
- iterator
- 파이썬
- Python Implementation
- 30. Substring with Concatenation of All Words
- Regular Expression
- 시바견
- Generator
- 운영체제
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- LeetCode
- shiba
- DWG
- data science
- kaggle
- Substring with Concatenation of All Words
- 컴퓨터의 구조
- 715. Range Module
- t1
- Convert Sorted List to Binary Search Tree
- Protocol
- Python
- 43. Multiply Strings
- 프로그래머스
- 315. Count of Smaller Numbers After Self
Archives
- Today
- Total
목록116. Populating Next Right Pointers in Each Node (1)
Scribbling
LeetCode: 116. Populating Next Right Pointers in Each Node
O(N) 메모리를 사용한다면 매우 쉬운 문제이지만, 아래 Follow-up을 반영하여 O(1) 메모리를 사용하여 푸는 것은 조금 생각이 필요하다. Constant Memory로 어찌 풀지 생각하다가 아래 조건에서 힌트를 얻었다. Node의 개수에 제한이 있다는 것. Perfect Binary Tree에서 이와 같은 조건은 곧 최대 높이로 직결된다. 이를 활용하면, 트리의 층마다 last node 주소를 저장해놓고 갱신하는 방식으로 풀 수 있다. """ # Definition for a Node. class Node: def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None): self.val..
Computer Science/Coding Test
2021. 11. 2. 14:42