일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 뭐든
- 월간
- 미드시청
- 영어공부
- 만화도
- 매일
- Daily Challenge
- 스탭퍼
- 사이드
- 프로젝트
- 운동
- Problem Solving
- realclass
- 쓰릴오브파이트
- 화상영어
- 읽기
- 개발자
- 파비최
- Writing
- English
- 링피트
- leetcode
- 3줄정리
- 잡생각
- 괜찮음
- 영어원서읽기
- 리얼 클래스
- 30분
- FIT XR
- 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