题解 | #斐波那契数列# | C++

斐波那契数列

https://www.nowcoder.com/practice/ee5d403c1172487f8c7915b3c3d924c6

#include <iostream>
using namespace std;

class Solution {
 public:
  int fib(int x) {
    if (x <= 2) return 1;
    return fib(x-1) + fib(x-2);
  }
};


int main() {
    int n;
    std::cin >> n;
    std::cout << Solution().fib(n);
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务