| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 스탭퍼
- realclass
- FIT XR
- 파비최
- leetcode
- 10분
- 잡생각
- 읽기
- 리얼 클래스
- 매일
- 링피트
- 영어원서읽기
- 월간
- 쓰릴오브파이트
- Writing
- 개발자
- Problem Solving
- 괜찮음
- 영어공부
- 미드시청
- English
- 뭐든
- 운동
- 화상영어
- 30분
- 3줄정리
- Daily Challenge
- 프로젝트
- 사이드
- 만화도
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.05.16 Today's Challenge 본문
https://leetcode.com/problems/swap-nodes-in-pairs/
Swap Nodes in Pairs - LeetCode
Can you solve this real interview question? Swap Nodes in Pairs - Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be chan
leetcode.com
또다시 링크드 리스트 ㅋㅋㅋ
class Solution:
def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]:
if not head:
return head
prev, cur, ans = None, head, head.next
while cur and cur.next:
adj = cur.next
if prev:
prev.next = adj
cur.next, adj.next = adj.next, cur
prev, cur = cur, cur.next
return ans or head반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.05.18 Today's Challenge (0) | 2023.05.18 |
|---|---|
| 2023.05.17 Today's Challenge (0) | 2023.05.17 |
| 2023.05.15 Today's Challenge (1) | 2023.05.15 |
| 2023.05.14 Today's Challenge (0) | 2023.05.14 |
| 2023.05.13 Today's Challenge (1) | 2023.05.13 |
Comments