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