把这个链表反转需要用到tmp使得前后结点做一个交换
class Solution {
public ListNode reverseList(ListNode head) {
// 让链表倒序,那么第一个结点就是null
// 做反转题一定要想到tmp
ListNode tmp = null;
ListNode pre = null;
ListNode cur = head;
while(cur != null) {
tmp = cur.next;
cur.next = pre;
pre = cur;
cur = tmp;
}
//pre成了头结点
return pre;
}
}