1. /**
    2. * @Description 一遍过了,可以奥
    3. * @Date 2022/1/19 11:09 下午
    4. * @Author wuqichuan@zuoyebang.com
    5. **/
    6. public class Solution {
    7. public ListNode swapPairs(ListNode head) {
    8. ListNode dummyHead = new ListNode();
    9. dummyHead.next = head;
    10. ListNode pre = dummyHead;
    11. while (pre.next != null && pre.next.next != null) {
    12. ListNode node1 = pre.next;
    13. ListNode node2 = pre.next.next;
    14. ListNode node2Next = node2.next;
    15. node1.next = node2Next;
    16. pre.next = node2;
    17. node2.next = node1;
    18. pre = node1;
    19. }
    20. return dummyHead.next;
    21. }
    22. }