## 写一个类似肥波那契数列的函数

f([1,1],10) ==> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

f([3,4],10) ==>[3, 4, 7, 11, 18, 29, 47, 76, 123, 199]

f([1,2,3],15) ==>[1, 2, 3, 6, 11, 20, 37, 68, 125, 230, 423, 778, 1431, 2632, 4841]

……  ……

0

```def feibo(list,n):
t=[]
if n <=len(list):
for i in range(n):
t.append(list[i])
return t
else:
t=list
for i in range(n-len(list)):
list.append(reduce(lambda a,b:a+b,t[i:]))
return t```
0

0

List  肥波(List my,int key){

if(key == 1 ) return my;

List list =  肥波(l,key-1);

long sum =  0;

for(Integer i : list){

sum+=i;

}

return list;

}

0

#### 引用来自“抛出异常的爱”的答案

List  肥波(List my,int key){

if(key == 1 ) return my;

List list =  肥波(l,key-1);

long sum =  0;

for(Integer i : list){

sum+=i;

}

return list;

}

0

#### 引用来自“Xsank”的答案

```def feibo(list,n):
t=[]
if n <=len(list):
for i in range(n):
t.append(list[i])
return t
else:
t=list
for i in range(n-len(list)):
list.append(reduce(lambda a,b:a+b,t[i:]))
return t```

0

0
Python 一行代码就行了
0

0
```public static void main(String[] args){
int[] array = getFibonacci(1,1,10);
System.out.println(Arrays.toString(array));
}
/**
* 用循环的方法
* @param startNo1
* @param startNo2
* @param arraySize
* @return
*/
public static int[] getFibonacci(int startNo1 , int startNo2 , int arraySize){
int[] fibonacciArray = null;
if(arraySize > 1){
fibonacciArray = new int[arraySize];
fibonacciArray[0] = startNo1;
fibonacciArray[1] = startNo2;
for(int i = 2 ; i < arraySize ; i++){
fibonacciArray[i] = fibonacciArray[i-1]+fibonacciArray[i-2];
}
}
return 	fibonacciArray;
}```
`非递归的斐波那契数列`

0

```# -*- encoding=utf-8 -*-
def f(a, l):
if len(a) > l:
return a
r = a[:]
for i in range(len(a), l):
n = 0;
for j in range(len(a)):
n = n + r[i-j-1]
r.append(n)
return r
if __name__ == '__main__':
print(f([1,1], 10))
print(f([3,4], 10))
print(f([1,2,3], 15))```