自己做题的大体思路加代码
ListNode tail, newHead = null;
// 因为链表要反转,所以原来的头部要转换成尾部,则其next初始为null
while (head != null) {
tail = head.next;
// 保存尚未改变顺序的下一跳
head.next = newHead;
// 反转链表
newHead = head;
// 保存新链表的表头
head = tail;
// 继续原本链表的顺序
}
return newHead;