0509. Fibonacci Number
Easy | DP | 12 ms (96.11%), 13.3 MB (90.24%)
Last updated
Was this helpful?
Easy | DP | 12 ms (96.11%), 13.3 MB (90.24%)
Last updated
Was this helpful?
Source: GitHub:
The Fibonacci numbers, commonly denoted F(n)
form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0
and 1
. That is,
Given n
, calculate F(n)
.
It is quite straightforward that two variables store information of F(n-1) and F(n-2) respectively. And the initialized values are 0 and 1 respectively.