Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 517 Bytes

206.md

File metadata and controls

28 lines (24 loc) · 517 Bytes

Leetcode 206. 反转链表

206. 反转链表

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var reverseList = function(head) {
    if(head == null || head.next == null){
        return head;
    }

    let newHead = reverseList(head.next);
    head.next.next = head;
    head.next = null;
    return newHead;
};