Climbing Stairs

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Intro DP — Remember Subanswers

Reuse smaller answers via a table or rolling variables.

int a = 1, b = 1;
for (int i = 2; i <= n; i++) {
    int c = a + b;
    a = b; b = c;
}
return b;
LeetCode
1/3
EasyIntro Dynamic ProgrammingLeetCode #70

Climbing Stairs

Ways(n) = ways(n-1)+ways(n-2). Fibonacci in disguise.

Examples

Example 1

Input

2

Output

2
Example 2

Input

3

Output

3

Stuck? Take a nudge

C++17