mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-31 19:13:42 +00:00
Update 10.1 斐波那契数列.md
补充斐波那契数列计算中关于取模运算与 int 溢出分析的说明。
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
|
||||
递归是将一个问题划分成多个子问题求解,动态规划也是如此,但是动态规划会把子问题的解缓存起来,从而避免重复求解子问题。
|
||||
|
||||
每一项取模后都小于 1000000007,两项相加不超过 2000000012,小于 int 的最大值 2147483647,因此用 int 不会溢出;不取模时 f(47) 就会超出 int 的范围。
|
||||
|
||||
```java
|
||||
public int fib(int n) {
|
||||
if (n <= 1)
|
||||
|
||||
Reference in New Issue
Block a user