题解 | #反转链表# --【Python3】

反转链表

http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca

class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None
class Solution:
    # 返回ListNode
    def ReverseList(self, pHead):
        prev = None
        cur = pHead
        while cur:
            nex = cur.next
            cur.next = prev
            prev = cur
            cur = nex
        return prev
全部评论

相关推荐

群星之怒:不是哥们,你就不好奇瘫痪三十年的老植物人是啥样的吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务