224ms Java solution:using array to store the nums


  • 0
    X
    public class Solution {
    public int climbStairs(int n) {
        int []counts = new int[n+1];
        counts[0]=0;
        counts[1]=1;
        if(n>=2){
            counts[2]=2;
        }
        
        for(int i = 3;i<n+1;i++){
            counts[i]=counts[i-1]+counts[i-2];
        }
        return counts[n];
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.