Leetcode - 24. Swap Nodes in Pairs
문제
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.
정답
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