Hello everyone, I am quick-frozen fish 🐟, a river front 💦, like the garish 💐, continuous sand sculpture 🌲 Welcome friends to add my wechat: Sudongyuer pull you into the group, discuss together, looking forward to growing together with everyone

Preface 🌧 ️

Algorithms are unfamiliar and familiar to the front-end people, and often we don’t value them as much as the back-end engineers do. But in fact, algorithms have an unshakable position for every programmer.

Because the development process is to convert the actual problem into the computer can recognize the instructions, that is, “data structure” said, “design the data structure, in the application of algorithms on the line”.

In today’s environment, algorithms have become an indispensable skill for front-end engineers. If we want to move beyond being application engineers writing business code, we need to understand algorithms and data structures.

Of course, learning is also focused, as the front end we do not need to fully grasp the algorithm like back-end development, some of the more partial, not practical type and solution method, as long as a little understanding.

The title 🦀

Print the linked list from end to end

Difficulty is simple

Enter the head node of a linked list and return the value of each node from end to end (as an array).

Example 1:

Input: head = [1,3,2] output: [2,3,1]Copy the code

Limitations:

0 <= List length <= 10000Copy the code

🌵

  • In and out is the stack, recursion is the stack
  • Use recursion to take the last element of the list into the array

Source 🔥

/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; *} * /
/ * * *@param {ListNode} head
 * @return {number[]}* /
var reversePrint = function(head) {

    if(! head){return []}
    const arr=[]
    const loop=(node,arr) = >{
        if(! node){return}
        loop(node.next,arr)
        arr.push(node.val)
    }
    loop(head,arr)
    return arr
  
};
Copy the code

Time complexity :O(n)

Space complexity :O(n)

Conclusion 🌞

So the “LeetCode” of The LeetCode of the algorithm refers to the end of the offshor-06 from the end to print the linked list ⚡️. There is no shortcut to the algorithm, so we can only write and practice more and summarize more. The purpose of the article is actually very simple, which is to urge myself to complete the algorithm practice and summarize and output. I hope everyone can like my essay, and I also hope to know more like-minded friends through the article. If you also like to toss, welcome to add my friend, sand sculpture together, together progress.

Making 🤖 : sudongyu

Personal blog 👨💻: Frozen fish blog

Vx 👦 : sudongyuer

Write in the last

Guys, if you like my words, give 🐟🐟 a thumbs up 👍 or follow ➕ to support me the most.

Add me on wechat: Sudongyuer, invite you to join the group, learn front end together, become a better engineer ~ (group QR code here -> front end to go to bed early, qr code expired to see the link in the boiling point of the comments, I will put the latest QR code in the comment section, of course, you can also add my wechat I pull you into the group, after all, I am also interesting front end, It’s not bad to know me 🌟 ~ PS: the company is in the front of recruitment recently, welcome friends to consult, coordinates chengdu, my VX: Sudongyuer, or direct delivery mailbox [[email protected]]