题解 | #斐波那契数列#
斐波那契数列
http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3
/* 动态规划: dp[n] = dp[n-1] + dp[n-2]; */ int Fibonacci(int n ) { if(n<3) return 1; int n1 = 1; int n2 = 1; for(int i = 3; i<=n; i++){ int temp = n2; n2 = n1 + n2; n1 = temp; } return n2; }