/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode pNode=head;
ListNode pReversedHead=null;
ListNode pPre=null;
while(pNode!=null){
ListNode pNext=pNode.next;
if(pNext==null){
pReversedHead=pNode;
}
pNode.next=pPre;
pPre=pNode;
pNode=pNext;
}
return pReversedHead;
}
}
class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
pReversedHead=None
pre=None
while(head!=None):
pNext=head.next
if(pNext==None):
pReversedHead=head
head.next=pre
pre=head
head=pNext
return pReversedHead