题解 | 斐波那契数列
斐波那契数列
https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ int re(int x) { if(x == 1 || x == 2) return 1; else if(x == 3) return 2; else return re(x - 1) + re(x - 2); } int Fibonacci(int n) { // write code here int ans = re(n); return ans; } };
这道题的知识点虽然写着记忆化搜索,dp,快速幂,但其实不用那么复杂。因为数据给的很小,只有40,只要把return的条件写的多一点,就能ac了。链接在此,牛币快来。#牛客春招刷题训练营#
#牛客春招刷题训练营#