All files / leetCode 0070.ts

100% Statements 9/9
100% Branches 0/0
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13  3x   3x   6x 6x 6x     3x    
export default function climbStairs(n: number): number {
  let dp = 1
 
  for (let i = 1, p = 0, q = 0; i <= n; ++i) {
    // dp[i] = dp[i - 2] + dp[i - 1]
    p = q
    q = dp
    dp = p + q
  }
 
  return dp
}