- Published on
Leetcode - 24. Swap Nodes in Pairs
- Authors
- Name
- Indo Yoon
Table of Contents
문제
[Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
LeetCode
](https://leetcode.com/problems/swap-nodes-in-pairs/)
정답
class Solution:
def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]:
dummy = head
while head and head.next:
adj = head.next
head.val, adj.val = adj.val, head.val
head = head.next.next
return dummy