completed till 06/07
This commit is contained in:
@@ -15,7 +15,11 @@ pub fn fibonacci(n: u32) -> u32 {
|
||||
//
|
||||
// Hint: use a `Vec` to memoize the results you have already calculated
|
||||
// so that you don't have to recalculate them several times.
|
||||
todo!()
|
||||
let mut fibNums = vec![0, 1];
|
||||
for i in 2..=n {
|
||||
fibNums.push(fibNums[(i - 1) as usize] + fibNums[(i - 2) as usize]);
|
||||
}
|
||||
fibNums[(n) as usize]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user