题目链接

    遍历链表,将每个节点的next指向新链表的头,然后该节点成为新链表头

    1. let reverseList = function(head) {
    2. // 遍历链表,将每个节点的next指向新链表的头,然后该节点成为新链表头
    3. let newListHead = null;
    4. while (head != null) {
    5. let tmp = head.next;
    6. head.next = newListHead;
    7. newListHead = head;
    8. head = tmp;
    9. }
    10. return newListHead;
    11. };