双指针解法
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
//建立双指针节点,一个在前,一个在后
ListNode cur=null,pre=head;
while(pre!=null){
//中间节点报错pre的下一个节点
ListNode t= pre.next;
//进行替换
pre.next=cur;
cur = pre;
pre= t;
}
head = cur;
return head;
}
}