题解 | #斐波那契数列# | Rust
斐波那契数列
https://www.nowcoder.com/practice/ee5d403c1172487f8c7915b3c3d924c6
use std::io::{self, *};
struct Solution{
}
impl Solution{
pub fn fib(&self, n: i32) -> i32 {
if n <= 2 {
return 1;
}
return Solution::fib(self, n-1) + Solution::fib(self, n-2);
}
}
fn main() {
let mut n : i32 = 0;
let mut input = String::new();
io::stdin().read_line(&mut input);
n = input.trim().parse().expect("");
print!("{}", Solution{}.fib(n));
}

