climbing-stairs
1.0.0
Climbing Stairs
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
#include <iostream>
2
3
using namespace
std;
4
5
class
Solution
6
{
7
public
:
8
int
climbStairs
(
int
n)
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
}
22
};
23
24
int
main
()
25
{
26
int
n = 5;
27
Solution
sol;
28
cout << sol.
climbStairs
(n) << endl;
29
return
0;
30
}
Solution
Definition
main.cpp:6
Solution::climbStairs
int climbStairs(int n)
Definition
main.cpp:8
main
int main()
Definition
main.cpp:24
main.cpp
Generated by
1.9.8