反转链表用了三个指针
附上代码:
public class Solution {
public ListNode ReverseList(ListNode head) {
if(head==null){
return null;
}
//三个指针
ListNode zuo = head;
ListNode mid = head.next;
if(head.next == null){
return head;
}
ListNode you = mid.next;
zuo.next = null;
while(you!=null){
mid.next = zuo;
zuo=mid;
mid=you;
you=you.next;
}
mid.next=zuo;
return mid;
}
}