Likou brush question day5 (print the linked list from the end to the beginning)

Article directory

topic

insert image description here

train of thought

Create an array to store the linked list from beginning to end, then reverse the array

the code

var reversePrint = function(head) {
    
    
    if(!head) return []
    let arr = [];
    while(head){
    
    
        arr.push(head.val);
        head = head.next;
    }
    return arr.reverse()
};

Guess you like

Origin blog.csdn.net/weixin_51610980/article/details/128388073