My java Solution(DP)


  • 1
    L
    public class Solution {
        public int climbStairs(int n) {
            int steps[] = new int[n + 1];
            for(int i = 0; i <= n; i++){
                if(0 == i || 1 == i)
                    steps[i] = 1;
                else{
                    steps[i] = steps[i - 1] + steps[i - 2];
                }
            }
            return steps[n];
        }
    }

Log in to reply
 

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