Python | Leetcode Python题解之第24题两两交换链表中的节点

题目:

题解:

python 复制代码
class Solution:
    def swapPairs(self, head: ListNode) -> ListNode:
        dummyHead = ListNode(0)
        dummyHead.next = head
        temp = dummyHead
        while temp.next and temp.next.next:
            node1 = temp.next
            node2 = temp.next.next
            temp.next = node2
            node1.next = node2.next
            node2.next = node1
            temp = node1
        return dummyHead.next
相关推荐
数据智能老司机30 分钟前
Python 实战遗传算法——遗传算法导论
python·算法·机器学习
让心淡泊1441 小时前
DAY 58 经典时序预测模型2
python
love530love1 小时前
怎么更新 cargo.exe ?(Rust 工具链)
人工智能·windows·python·rust·r语言
闲人编程1 小时前
PyQt6 进阶篇:构建现代化、功能强大的桌面应用
数据库·python·oracle·gui·脚本·pyqt6·软件
不枯石2 小时前
Python计算点云的欧式、马氏、最近邻、平均、倒角距离(Chamfer Distance)
python·计算机视觉
雷达学弱狗2 小时前
anaconda本身有一个python环境(base),想用别的环境就是用anaconda命令行往anaconda里创建虚拟环境
开发语言·python
麻雀无能为力2 小时前
python 自学笔记13 numpy数组规整
笔记·python·numpy
站大爷IP3 小时前
Python多线程与多进程性能对比:从原理到实战的深度解析
python
j_xxx404_3 小时前
数据结构:单链表的应用(力扣算法题)第一章
c语言·数据结构·算法·leetcode
东方佑3 小时前
Python音频分析与线性回归:探索声音中的数学之美
python·音视频·线性回归