首页 > 其他分享 >《剑指Offer》-10-斐波那契数列

《剑指Offer》-10-斐波那契数列

时间:2023-02-16 05:22:05浏览次数:40  
标签:10 Offer int long 斐波 那契

	long long mod = 1e9 + 7;
	int fib(int n) {
		if (n < 2) return n;
		int prepre = 0, pre = 1, res;

		for (int i = 2; i <= n; i++) {
			res = (prepre % mod + pre % mod) % mod;
			prepre = pre;
			pre = res;
		}
		return res;
	}

感觉效率有点低

标签:10,Offer,int,long,斐波,那契
From: https://www.cnblogs.com/yaocy/p/17125335.html

相关文章