#24

Swap Nodes in Pairs

pupil · 570 · lc medium +29 · 69% accepted · 13,084 likes · top 76%

play →

Description

Exchange every pair of adjacent nodes in the linked list and return the new head. Only node pointers may be rearranged; node values must not be modified.

Code

1
2
3
4
5
6
7
8