climbing-stairs 1.0.0
Climbing Stairs
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

int climbStairs (int n)
 

Detailed Description

Definition at line 5 of file main.cpp.

Member Function Documentation

◆ climbStairs()

int Solution::climbStairs ( int  n)
inline

Definition at line 8 of file main.cpp.

9 {
10 if (n == 1)
11 return 1;
12 int prev1 = 2;
13 int prev2 = 1;
14 for (int i = 3; i <= n; ++i)
15 {
16 int current = prev1 + prev2;
17 prev2 = prev1;
18 prev1 = current;
19 }
20 return prev1;
21 }

Referenced by main().


The documentation for this class was generated from the following file: