题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode cur = head;
ListNode pre = null;
while(cur!=null){
ListNode curNext = cur.next; //下一个节点
cur.next = pre;//当前节点的指针指向pre
pre = cur;//pre更新为当前节点
cur = curNext;//当前节点指向下一个节点,即前面存储的curNext
}
return pre;
}
}
