auto-generated entry for Climbing Stairs. the solution files are available below.
solution files
- C++
climbing-stairs/synced-solution.cpp - Python
climbing-stairs/synced-solution.py - TypeScript
climbing-stairs/synced-solution.ts
Collected C++, Python, TypeScript solutions for climbing stairs. Add a dedicated write-up later if you want deeper notes.
auto-generated entry for Climbing Stairs. the solution files are available below.
climbing-stairs/synced-solution.cppclimbing-stairs/synced-solution.pyclimbing-stairs/synced-solution.tsclass Solution:
def climbStairs(self, n: int) -> int:
a, b = class="syntax-number">1, class="syntax-number">1
for _ in range(n-class="syntax-number">1):
a, b = b, a+b
return b
class Solution {
public:
int climbStairs(int n) {
int a = class="syntax-number">1, b = class="syntax-number">1;
for (int i = class="syntax-number">1; i < n; i++) { int c = a+b; a = b; b = c; }
return b;
}
};
function climbStairs(n: number): number {
let a = class="syntax-number">1, b = class="syntax-number">1;
for (let i = class="syntax-number">1; i < n; i++) [a, b] = [b, a + b];
return b;
}