题解 | #反转链表#

反转链表

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

-- 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==None: return pHead a = ListNode(0) a.next = pHead p = pHead.next pHead.next=None while(p!=None): q=p.next p.next=a.next a.next=p p=q return a.next

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务