解题思路:
迭代(双指针)
class Solution {public ListNode reverseList(ListNode head) {ListNode cur = head, pre = null;while(cur != null) {ListNode tmp = cur.next; // 暂存后继节点 cur.nextcur.next = pre; // 修改 next 引用指向pre = cur; // pre 暂存 curcur = tmp; // cur 访问下一节点}return pre;}
}