// 思路:迭代
class Solution {
public ListNode reverseList(ListNode head) {
// 判断链表是否为空或者只有一个结点
if(head == null || head.next == null){
return head;
}
ListNode cur = head;
ListNode next = null;
ListNode reverseHead = new ListNode(0);
while(cur != null){
next = cur.next;
cur.next = reverseHead.next;
reverseHead.next = cur;
cur = next; //注意将 cur 后移
}
return reverseHead.next;
}
}