373. Swap Nodes in Pairs
MediumLinked List
Swap every two adjacent nodes and print the list (a leftover last node stays in place).
Input format
Line 1: n Line 2: n values
Output format
The list after swapping.
Example 1
Input
4 1 2 3 4
Output
2 1 4 3
Example 2
Input
1 1
Output
1
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…