题解 | #跳台阶扩展问题# | Rust

跳台阶扩展问题

https://www.nowcoder.com/practice/953b74ca5c4d44bb91f39ac4ddea0fee

use std::io::{self, *};

struct Solution {
    n : i32
}

impl Solution {
    fn countWays(&self) -> i32 {
        let mut prefix : i32 = 0;
        let mut ans : i32 = 0;
        for i in 0..self.n {
            ans = 1 + prefix;
            prefix += ans;
        }
        return ans;
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    let n:i32 = input.trim().parse().expect("");;
    print!("{}", Solution{n:n}.countWays());
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务