题目链接
迭代
class Solution { public ListNode reverseList(ListNode head) { ListNode pre = null,cur = head,next = null; while(cur!=null){ //将cur.next存起来 next = cur.next; //cur.next指向pre cur.next = pre; //将当前节点赋给pre pre = cur; //将当前节点的下一个节点赋给当前节点 cur = next; } //返回当前节点 return pre; } }