|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <openset.wang@gmail.com> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +## 509. Fibonacci Number (Easy) |
| 9 | + |
| 10 | +<p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +F(0) = 0, F(1) = 1 |
| 14 | +F(N) = F(N - 1) + F(N - 2), for N > 1. |
| 15 | +</pre> |
| 16 | + |
| 17 | +<p>Given <code>N</code>, calculate <code>F(N)</code>.</p> |
| 18 | + |
| 19 | +<p> </p> |
| 20 | + |
| 21 | +<p><strong>Example 1:</strong></p> |
| 22 | + |
| 23 | +<pre> |
| 24 | +<strong>Input:</strong> 2 |
| 25 | +<strong>Output:</strong> 1 |
| 26 | +<strong>Explanation:</strong> F(2) = F(1) + F(0) = 1 + 0 = 1. |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p><strong>Example 2:</strong></p> |
| 30 | + |
| 31 | +<pre> |
| 32 | +<strong>Input:</strong> 3 |
| 33 | +<strong>Output:</strong> 2 |
| 34 | +<strong>Explanation:</strong> F(3) = F(2) + F(1) = 1 + 1 = 2. |
| 35 | +</pre> |
| 36 | + |
| 37 | +<p><strong>Example 3:</strong></p> |
| 38 | + |
| 39 | +<pre> |
| 40 | +<strong>Input:</strong> 4 |
| 41 | +<strong>Output:</strong> 3 |
| 42 | +<strong>Explanation:</strong> F(4) = F(3) + F(2) = 2 + 1 = 3. |
| 43 | +</pre> |
| 44 | + |
| 45 | +<p> </p> |
| 46 | + |
| 47 | +<p><strong>Note:</strong></p> |
| 48 | + |
| 49 | +<p>0 ≤ <code>N</code> ≤ 30.</p> |
| 50 | + |
| 51 | + |
| 52 | +### Related Topics |
| 53 | + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] |
| 54 | + |
| 55 | +### Similar Questions |
| 56 | + 1. [Climbing Stairs](https://github.com/openset/leetcode/tree/master/problems/climbing-stairs) (Easy) |
| 57 | + 1. [Split Array into Fibonacci Sequence](https://github.com/openset/leetcode/tree/master/problems/split-array-into-fibonacci-sequence) (Medium) |
| 58 | + 1. [Length of Longest Fibonacci Subsequence](https://github.com/openset/leetcode/tree/master/problems/length-of-longest-fibonacci-subsequence) (Medium) |
0 commit comments