15. Reverse list
problem:
After entering a list inverted list, the new list of the output header.
solve:
thought:
This question is typical routine to reverse a linked list, with a typical direct reversal of the list
python code:
# -*- 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
p=pHead
q=None
while(p!=None):
r=q
q=p
p=p.next
q.next=r
return q