Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of jumping steps by python

Shulou Source: shulou.com Published: 2022-05-31 14:05:23 10月04日 Update

This article introduces the relevant knowledge of "how to solve the step jumping problem of python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The problem of jumping steps

A frog can jump up one step or two steps at a time. It can also jump to level n. Find out how many ways the frog can jump on an n-step step.

Code # A frog can jump up one step or two steps at a time. It can also jump to level n. Find out how many ways the frog can jump on an n-step step. #-*-coding:utf-8-* -''inductive method to find out the rule class Solution: def jumpFloorII (self, number): return 2 steps * (number-1)' Recursive implementation class Solution: def jumpFloorII (self) Number): if number==1: return 1 else: return 2*self.jumpFloorII (number-1) 'non-recursive implementation class Solution: def jumpFloorII (self, number): sum = 1 for i in range (1 Number): sum * = 2 return sum'''if _ name__ ='_ _ main__': sl = Solution () print (sl.jumpFloorII (1)) print (sl.jumpFloorII (2)) print (sl.jumpFloorII (3)) print (sl.jumpFloorII (4)) "python how to solve the step jumping problem" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Steps frogs questions content more knowledge recursion practicality learning next code dilemma reality induction situation articles cases editing websites industries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Microsoft Shulou Tech Info MySQL