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”.

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 🦀

Sword refers to Offer 10-II. Frog jump step problem

Difficulty is simple

A frog can jump up one step or two steps at a time. Find out how many ways the frog can jump up n steps.

1e9+7 (1000000007) is required for the answer. If the initial calculation result is 1000000008, return 1.

Example 1:

Input: n = 2 Output: 2Copy the code

Example 2:

Input: n = 7 Output: 21Copy the code

Example 3:

Input: n = 0 Output: 1Copy the code

Tip:

  • 0 <= n <= 100

🌵

  • Dynamic programming and divide and conquer (recursion)
  • In the future, if you encounter such problems, try to recall this routine, first create a new initialization array, and then start stacking

Source 🔥

/ * * *@param {number} n
 * @return {number}* /
var numWays = function(n) {

const numWays=[1.1.2]

for(let i=3; i<=n; i++){ numWays[i]=(numWays[i-1]+numWays[i-2]) %1000000007
}
return numWays[n]
};
Copy the code

Time complexity :O(n)

Space complexity :O(n)

Conclusion 🌞

So the “LeetCode” of The LeetCode of the algorithm chapter refers to the offer-10-II frog jump step problem ⚡️. 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. But I love 🔥, and I like that 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, and progress together.

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]]