题解 | #跳台阶# | Rust

跳台阶

https://www.nowcoder.com/practice/bfb2a2b3cdbd4bd6bba0d4dca69aa3f0

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

struct Solution {}

impl Solution {
    pub fn countWays(&self, n: i32) -> i32 {
        if n <= 1 {
            return 1;
        }
        if n <= 2 {
            return 2;
        }
        return Solution::countWays(self, n-2) + Solution::countWays(self, n-1);
    }
}

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

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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