题目描述

输入一个链表,反转链表后,输出新链表的表头。

思路:
两个指针,循环调节指针方向。

代码:

public class Solution {
    public ListNode ReverseList(ListNode head) {
        ListNode pre = null;
        ListNode p = null;
        while(head != null){
            p = head.next;
            head.next = pre;
            pre = head;
            head = p;
        }
        return pre;
    }
}