509. Fibonacci Number Easy

@problem@discussion
#Math#Dynamic Programming#Recursion#Memoization



1/**
2 * [509] Fibonacci Number
3 *
4 * 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,
5 * 
6 * F(0) = 0, F(1) = 1
7 * F(n) = F(n - 1) + F(n - 2), for n > 1.
8 * 
9 * Given n, calculate F(n).
10 *  
11 * Example 1:
12 * 
13 * Input: n = 2
14 * Output: 1
15 * Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
16 * 
17 * Example 2:
18 * 
19 * Input: n = 3
20 * Output: 2
21 * Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
22 * 
23 * Example 3:
24 * 
25 * Input: n = 4
26 * Output: 3
27 * Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	0 <= n <= 30
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/fibonacci-number/
38// discuss: https://leetcode.com/problems/fibonacci-number/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn fib(n: i32) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_509() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.