MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / fib

Method fib

509-fibonacci-number.rs:8–16  ·  view source on GitHub ↗
(n: i32)

Source from the content-addressed store, hash-verified

6
7impl Solution {
8 pub fn fib(n: i32) -> i32 {
9 if n == 0 {
10 0
11 } else if n == 1 {
12 1
13 } else {
14 Self::fib(n-1) + Self::fib(n-2)
15 }
16 }
17
18 pub fn fib_dp(n: i32) -> i32 {
19 let mut dp = vec![0; 31];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected