面试-算法
- 费罗列算法
def test(num):i=0st=1end=1tem=1while i <=num:i+=1if i <=2:print(tem)else:tem = st+endst=endend=tem
2.冒泡 排序
def test(l_list):for i in range(len(l_list)):for j in range(len(l_list)-i-1):if l_list[j] > l_list[j+1]:l_list[j],l_list[j+1] = l_list[j+1],l_list[j]
- 快排
拿出第一个数为标准,比它小的排左边,比它大的排右边,循环操作
```python
def test(l):
if len(l)<=2:return l
else:tem = l[0]less = [i for i in l[1:] if i<=tem]greater = [i for i in l[1:] if i>tem]return test(less) + [tem] + test(greater)
```
- 插入
def test(l):for i in range(1,len(l)):cur = l[i]j=iwhile l[j-1]<cur and j>=0:l[j] = l[j-1]j-=1l[i]=curreturn l