1. 程式人生 > >70. Climbing Stairs (DP)

70. Climbing Stairs (DP)

public pre div int n) spa pub climb code

 1 class Solution {
 2     public int climbStairs(int n) {
 3         int[] s = new int[n + 1];
 4         s[1] = 1; s[0] = 1;
 5         for(int i = 2; i <= n; i++) {
 6             s[i] = s[i - 1] + s[i - 2];
 7         }
 8         return s[n];
 9         
10     }
11 }

70. Climbing Stairs (DP)