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