package com.example.leetcode;
public class ReverseList {
public ListNode reverse(ListNode head){
if (head==null){
return null;
}
ListNode pre=head;
ListNode current=head.next;
//最初的时候要指向null
pre.next=null;
while (current!=null){
//先判断下个节点有没有值
ListNode next =current.next;
//将当前节点指向前一个节点
current.next=pre;
//向后移动
pre=current;
//向后移动
current=next;
}
return pre;
}
}



