# 斐波拉切三种求法(Three solutions of fiborache)-其他

## 斐波拉切三种求法(Three solutions of fiborache)

``# 暴力求解def func1(num: int):    if num < 2:        return num    return func1(num - 1) + func1(num - 2)# 去重队列def recurse(li: list, num: int):    if num == 0:        return 0    if num == 1:        return 1    if li[num] != 0:        return li[num]    li[num] = recurse(li, num - 1) + recurse(li, num - 2)    return li[num]def func2(num: int):    li = [0 for _ in range(num + 1)]    return recurse(li, num)# 双指针def func3(num:int):    pre1 = 0    pre2 = 1    res = 0    for i in range(0,num-1): # 少循环2次：0，1        res = pre1 + pre2        pre1 = pre2        pre2 = res    return resprint(func1(3))print(func2(3))print(func3(3))``
————————
``# 暴力求解def func1(num: int):    if num < 2:        return num    return func1(num - 1) + func1(num - 2)# 去重队列def recurse(li: list, num: int):    if num == 0:        return 0    if num == 1:        return 1    if li[num] != 0:        return li[num]    li[num] = recurse(li, num - 1) + recurse(li, num - 2)    return li[num]def func2(num: int):    li = [0 for _ in range(num + 1)]    return recurse(li, num)# 双指针def func3(num:int):    pre1 = 0    pre2 = 1    res = 0    for i in range(0,num-1): # 少循环2次：0，1        res = pre1 + pre2        pre1 = pre2        pre2 = res    return resprint(func1(3))print(func2(3))print(func3(3))``