Brush questions, climb stairs, recursion, backtracking, dynamic programming_My blog is gone

class=”markdown_views prism-atom-one-dark”> WeChat search: programming notebook, get more dry goods knowledge WeChat search: programming notebook, get more dry goods knowledge WeChat search : Programming notebook, get more dry goods knowledge Click the blue word above to follow me, let’s learn programming together Welcome friends to share, repost, private message, appreciate. Today, I will share a ByteDance interview question: Stair Climbing Ⅱ. Description of topic: A step has a total of n levels. If you can skip 1 level at a time, you can also skip 2 levels, but cannot be continuous Skip 2 levels twice. Find how many total jumps there are in total. Analysis: If there is no constraint of “cannot jump 2 levels twice in a row”, then we can easily write the following recursive function: int climb(int n) { if (n == 1 || n == 2) { return n; } return climb(n – 1) + climb(n – 2); } In the above code, it is bound to include the method of jumping 2 levels twice in a row. So, we try to remove these redundant jumps. To get rid of these jumps, we need to get rid of twice, three, four times… jump 2 level jumping…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索