HTMLify

LeetCode - Fibonacci Number - Rust
Views: 192 | Author: abh
impl Solution {
    pub fn fib(n: i32) -> i32 {
        if (n == 0){
            return 0;
        }
        if (n == 1){
            return 1;
        }
        let mut f=0;
        let mut s=1;
        let mut t;
        for _ in 0..n+1{
            t = f + s;
            s = f;
            f = t;
        }
        return s;
    }
}

Comments

abh 2023-11-02 09:06

I done it with variables insted of array, because I don't know about them at that time.