给你一个链表两两交换其中相邻的节点并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题即只能进行节点交换。示例 1输入head [1,2,3,4]输出[2,1,4,3]思路新建虚拟头结点简化头部交换逻辑用cur遍历每次处理一组两个节点设三组指针first当前第一个、second当前第二个、nextPair下一组起点完成交换cur→second→first→下一组cur跳到first继续循环class Solution: def swapPairs(self, head: Optional[ListNode]) - Optional[ListNode]: dummy ListNode(0, head) cur dummy while cur.next and cur.next.next: first cur.next second cur.next.next next_p second.next cur.next second second.next first first.next next_p cur first return dummy.next