js 链表反转

/* 
* function ListNode(val, next) {
*     this.val = (val===undefined ? 0 : val)
*     this.next = (next===undefined ? null : next)
* }
*/

    function reverse(l){
        let v = ''
        while(l){
            v += l.val;
            l = l.next
        }
        return v.split('').reduce((p,c)=>{
            c = new ListNode(+c)
            c.next = p
            return c
        },null)
    }
原文地址:https://www.cnblogs.com/selfdef/p/13766993.html