Problem
Given a linked list, swap every two adjacent nodes and return its head.
Example
1 | Given 1->2->3->4, you should return the list as 2->1->4->3. |
Note
Can solve this problem by using only constant extra space.
Solution
Method: Iterative
Time Complexity: O(n)
Space Complexity: O(1)
1 | # Definition for singly-linked list. |