Skip to main content

70. Climbing Stairs

·46 words·1 min· loading
Table of Contents

problem

IDEA
#

  • It’s a simple DP problem.

Code/Solution
#

class Solution {

    public int climbStairs(int n) {

        if (n <= 2) return n;
        
        int[] arr = new int[n];
        arr[0] = 1;
        arr[1] = 2;
        
        for(int i=2; i<n;i++){
            arr[i] = arr[i-1]+arr[i-2];
        }
        return arr[arr.length-1];
    }

}