My accepted java solution


  • 4
    S
    public class Solution {
        public int climbStairs(int n) {
         int[] tmp = new int[n];
            if (n < 2)   return 1;
            tmp[0] = 1;
            tmp[1] = 2;
            for (int i = 2; i < n; i++)
                tmp[i] = tmp[i-1] + tmp[i-2];
            return tmp[n-1];
        }
    }

  • 0
    K

    It looks like the Fibonacci sequence. Was that by design or by accident?


  • 0
    S

    It is memorization or dp by bottom up approach....


  • 0
    B

    The question is basically to compute the nth fibonacci number since the nth stair depends on the n-1 stair(1 step) + the n-2 stair(2 steps)


Log in to reply
 

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