爬楼梯稍微改一下初始参数。 1impl Solution {2 pub fn fib(n: i32) -> i32 {3 if n == 0 {4 return 0;5 } else if n == 1 {6 return 1;7 }8 9 let mut data = vec![0, 1];10 let mut next = 0;11 12 let mut i = 1;13 while i < n {14 data[next] = data[0] + data[1];15 i += 1;16 if i == n {17 return data[next];18 }19 20 if next == 0 {21 next = 1;22 } else {23 next = 0;24 }25 }26 data[next]27 }28}