题目描述:
方法:迭代(双指针)
class Solution { public ListNode reverseList(ListNode head) { ListNode cur = head, pre = null; while(cur != null) { ListNode tmp = cur.next; // 暂存后继节点 cur.next cur.next = pre; // 修改 next 引用指向 pre = cur; // pre 暂存 cur cur = tmp; // cur 访问下一节点 } return pre; } }
标签:24,pre,ListNode,cur,Offer,next,链表,null From: https://www.cnblogs.com/zhz123567/p/17462482.html