Climbing Stairs in Rust

impl Solution {
    fn climb_stairs(n: i32) -> i32 {
        // Create a vector to store the distinct ways to climb for each number of steps
        let mut dp = vec![0; (n + 1) as usize];

        // Base cases:
        // There is only one way to climb 0 steps (do nothing)
        dp[0] = 1;
        // There is only one way to climb 1 step (take one step)
        dp[1] = 1;

        // Iterate from 2 to n
        for i in 2..=n {
            // The number of distinct ways to climb i steps is the sum of:
            // 1. The number of distinct ways to climb (i - 1) steps (taking one step from the previous step)
            // 2. The number of distinct ways to climb (i - 2) steps (taking two steps from two steps before)
            dp[i as usize] = dp[(i - 1) as usize] + dp[(i - 2) as usize];
        }

        // Return the number of distinct ways to climb n steps
        dp[n as usize]
    }
}

PrevNext