Climbing stairs java solution


  • 0
    V

    public class Solution {

    public int climbStairs(int n) {
    
        if(n == 0 || n == 1 || n == 2){
            return n;
        }
    
        int[] ways = new int[n + 1];
        ways[0] = 0;
        ways[1] = 1;
        ways[2] = 2;
        
        for(int i = 3 ; i <= n; i++){
            ways[i] = ways[i-1] + ways[i-2];
        }
        
        return ways[n];
    }
    

    }


Log in to reply
 

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