解题思路:
pre ,cur双指针
需要通过tmp暂存cur的下一个位置,以方便cur的下一步移动
class Solution {
public ListNode reverseList(ListNode head) {
ListNode pre = null;
ListNode cur = head;
while (cur != null) {
ListNode tmp = cur.next;
cur.next = pre;
pre = cur;
cur = tmp;
}
return pre;
}
}