BM1 反转链表

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function ReverseList(pHead)
{
    // write code here

    if(!pHead)   return pHead
    if(pHead!== null && pHead.next == null) return pHead
     let pre = null
          let cur = pHead
    while(cur) {
       
        let temp = cur.next
        cur.next = pre
        pre = cur
        cur = temp
    }
     return pre
    
}
module.exports = {
    ReverseList : ReverseList
};

 

 

 

 

posted @ 2022-03-27 21:41  方头小小狮  阅读(31)  评论(0)    收藏  举报