Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 127 Accepted Submission(s): 89 Problem Description Mr. Frog has n sticks, whose lengths are 1,2, 3⋯n respectively. Wallice is a bad ma…
著名的斐波拉契数列(Fibonacci),除第一个和第二个数外,任意一个数都可由前两个数相加得到: 1, 1, 2, 3, 5, 8, 13, 21, 34, ... 如果用Python的列表生成式,很难写出来 如果用函数和生成器的话就很容易了 def fib(max): n, a, b = 0, 0, 1 while n < max: print(b) a, b = b, a + b n = n + 1 return 'done'需要注意上面的 a,b = b, a+b 相当于: t = (b…
斐波拉契数列是指这样一个数列: F(1)=1; F(2)=1; F(n)=F(n-1)+F(n); public class Solution { public int Fibonacci(int n) { int preNum = 1; int prePreNum = 0; int result = 0; if(n ==0){ return 0; } if(n == 1){ return 1; } for(int i = 2; i <= n; i ++){ result = preNum +…