class Solution {
public ListNode reverseList(ListNode head) {
if(head==null||head.next==null){
return head;
}
ListNode p=null;
ListNode q=null;
while(head!=null){
q=head.next;//把head.next的位置给q
head.next=p;//把p的位置给head.next
p=head;//把head的位置给p
head=q;//把q的位置给head
}
return p;
}
}
class Solution {
public ListNode reverseList(ListNode head) {
if(head==null||head.next==null){
return head;
}
ListNode second=head.next;
ListNode reverseHead=reverseList(second);
second.next=head;
head.next=null;
return reverseHead;
}
}