反转链表
反转链表
http://www.nowcoder.com/questionTerminal/75e878df47f24fdc9dc3e400ec6058ca
三个变量就够用了
pre cur next
public ListNode ReverseList3(ListNode head) {
ListNode pre = null;
ListNode next = null;
while (head != null) {
// 记录next 反转后会丢失
next = head.next;
// 反转 链表一分为二了
head.next = pre;
// 前端链表的头部
pre = head;
// 后端链表的头部
head = next;
}
return pre;
}
传音控股公司福利 316人发布