일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- English
- 미드시청
- Daily Challenge
- 스탭퍼
- 리얼 클래스
- 30분
- 프로젝트
- 사이드
- 쓰릴오브파이트
- FIT XR
- 운동
- 괜찮음
- realclass
- 읽기
- 만화도
- 월간
- 파비최
- 링피트
- Writing
- 3줄정리
- 영어공부
- Problem Solving
- 잡생각
- leetcode
- 개발자
- 영어원서읽기
- 화상영어
- 뭐든
- 매일
- 10분
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.09.05 Today's Challenge 본문
https://leetcode.com/problems/copy-list-with-random-pointer/
Copy List with Random Pointer - LeetCode
Can you solve this real interview question? Copy List with Random Pointer - A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy [https://en.
leetcode.com
링크드 리스트 문제
class Solution:
def __init__(self):
self.visited = {}
def copyRandomList(self, head: 'Optional[Node]') -> 'Optional[Node]':
if not head:
return None
if head in self.visited:
return self.visited[head]
newNode = Node(head.val)
self.visited[head] = newNode
newNode.next = self.copyRandomList(head.next)
newNode.random = self.copyRandomList(head.random)
return newNode
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.09.07 Today's Challenge (0) | 2023.09.07 |
---|---|
2023.09.06 Today's Challenge (0) | 2023.09.06 |
2023.09.04 Today's Challenge (0) | 2023.09.04 |
2023.09.03 Today's Challenge (0) | 2023.09.03 |
2023.09.02 Today's Challenge (0) | 2023.09.02 |
Comments