Solution 1: time limit exceeded
Time: O(2^n)
I forget to remove “static” on ways and it accumulates the results of all test cases.
|
|
A better alternative12345public int climbStairs(int n) { if(n == 0 || n == 1) return 1; return climbStairs(n-1) + climbStairs(n-2);}
Solution 2: accepted 0ms
Time: O(n)
Straight fibonacci: f(n) = f(n-1) + f(n-2)
|
|