Js used to prove safety brush offer (inverted list)

Title Description

After entering a list inverted list, the new list of the output header.

Cattle off network link

js code

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function ReverseList(pHead)
{
    // write code here
    if (!pHead) return null 
    let p = pHead
    let q = pHead.next
    let head = pHead
    head.next = null
    while (q) {
        p = q
        q = q.next
        p.next = head
        head = p
    }
    return head
}

Guess you like

Origin www.cnblogs.com/dpnlp/p/yongjs-shua-jian-zhioffer-fan-zhuan-lian-biao.html