Python | Leetcode Python题解之第206题反转链表

题目:

题解:

python 复制代码
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        newHead = ListNode(0)
        newHead.next = None
        h = head
        while h:
            cur = ListNode(h.val)
            cur.next = newHead.next
            newHead.next = cur
            h = h.next
        
        return newHead.next
相关推荐
苏苏susuus10 分钟前
核密度估计(KDE)与高斯核(概念分享)
人工智能·python·ocr
宸津-代码粉碎机1 小时前
微服务线上踩坑复盘:接口超时、负载倾斜隐形问题根治方案(生产级配置)
java·大数据·人工智能·python·spring
速易达网络1 小时前
Python + Tkinter 实现基于 TCP/IP 的局域网聊天工具
python·信息与通信
多多鼠1 小时前
System Prompt 的“版本漂移”问题:从变更管理到 A/B 测试体系
开发语言·网络·人工智能·python·langchain
昔我往昔1 小时前
pytest日志问题排查记录
python·pytest
Python自动化直播1 小时前
用 Python 爬虫给 AI 直播间做数据反馈机制
人工智能·python·ai·直播
努力学习的代码小白2 小时前
源码学习04
python
圣保罗的大教堂2 小时前
leetcode 3742. 网格中得分最大的路径 中等
leetcode
Ray Wang2 小时前
Context上下文工程
python·学习·ai编程
梦影_2 小时前
Langchain简单快速上手教程(五)——聊天模型之流式传输
java·数据库·人工智能·python·langchain