In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to solve the problem of frog jumping steps in python". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to solve the problem of frog jumping steps in python" can help you solve your doubts.
Frogs jump steps # A frog can jump one step at a time, or two steps at a time. Find out the total number of jumping methods for the frog to jump on an n-step step (different order is a different result). #-*-coding:utf-8-*-class Solution: # stupid method: traverse three layers, find all the permutations in each layer, and then remove def jumpFloor (self, number): if number%2==0: min = number//2 else: min = number//2+1 max = number n = 0 for num in range (min) Max+1): for i in range (2**num): K = I temp = 0 for j in range (num): massik-(2*int (kamp 2)) k = int (kmax 2) if masks 0: Temp + = 1 else: temp + = 2 if temp==number: return n # recursively implement def rec_jump (self N): if nameplate 1: return 1 elif nameplate 2: return 2 else: return self.rec_jump (nmur1) + self.rec_jump (nMuth2) # non-recursive implementation, mathematical inference method to achieve f (n) = f (nMul 1) + f (NMAE 2)-- > sum=t1+t2 def lt_jump (self) N): T1 = 1 T2 = 2 if n = 1: return 1 elif n = = 2: return 2 else: for i in range (2LGI n): sum = T1 + T2 T1 = T2 T2 = sum return sum # list implementation def lt_list_jump (self N): res_arr = [1Magazine 2] for i in range (2 N): res_arr.append (res_ arr [I-1] + res_ arr [I-2]) return res_ arr [n-1] if _ _ name__ ='_ _ main__': sl = Solution () print (sl.jumpFloor (15)) print (sl.rec_jump (15)) print (sl.lt_jump (15)) print (sl.lt_list_jump (15)) This article "how to solve the problem of frog jumping steps in python" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.