斐波那契的小改动。 1impl Solution {2 pub fn tribonacci(n: i32) -> i32 {3 if n == 0 {4 return 0;5 } else if n == 1 {6 return 1;7 } else if n == 2 {8 return 1;9 }10 11 let mut data = vec![0, 1, 1];12 let mut next = 0;13 14 let mut i = 2;15 while i < n {16 data[next] = data[0] + data[1] + data[2];17 i += 1;18 if i == n {19 return data[next];20 }21 22 next = (next + 1) % 3;23 }24 data[next]25 }26}