File tree Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change 1
1
{
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 2 ,
4
+ "metadata" : {},
2
5
"cells" : [
3
6
{
4
- "cell_type" : " code" ,
5
- "execution_count" : null ,
6
7
"metadata" : {},
7
- "outputs" : [],
8
8
"source" : [
9
- " dp = [0 for _ in range(10000000)]\n " ,
10
- " \n " ,
11
- " \n " ,
12
9
" def fib(n):\n " ,
13
- " if n == 0:\n " ,
14
- " return dp[0]\n " ,
15
- " if n == 1:\n " ,
16
- " return dp[1]\n " ,
17
- " dp[0] = 0\n " ,
18
- " dp[1] = 1\n " ,
10
+ " dp = [0, 1]\n " ,
11
+ " if n == 0 or n == 1:\n " ,
12
+ " return dp[n]\n " ,
19
13
" for i in range(2, n + 1):\n " ,
20
- " dp[i] = dp[i - 1] + dp[i - 2]\n " ,
14
+ " dp.append( dp[i - 1] + dp[i - 2]) \n " ,
21
15
" return dp[n]\n " ,
22
16
" \n " ,
23
17
" \n " ,
24
18
" print(fib(100))"
25
- ]
19
+ ],
20
+ "cell_type" : " code" ,
21
+ "outputs" : [],
22
+ "execution_count" : null
26
23
}
27
- ],
28
- "metadata" : {},
29
- "nbformat" : 4 ,
30
- "nbformat_minor" : 2
24
+ ]
31
25
}
You can’t perform that action at this time.
0 commit comments