Skip to content

Instantly share code, notes, and snippets.

@vimiix
Created March 6, 2018 08:32
Show Gist options
  • Save vimiix/869340fc3ce4c8b111d4e8877704fba7 to your computer and use it in GitHub Desktop.
Save vimiix/869340fc3ce4c8b111d4e8877704fba7 to your computer and use it in GitHub Desktop.
翻转单链表
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# 返回ListNode
def ReverseList(self, pHead):
# write code here
if pHead is None or pHead.next is None:
return pHead
pre = None
cur = pHead
new_head = cur
while cur:
new_head = cur
next = cur.next
cur.next = pre
pre = cur
cur = next
return new_head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment