/
stairs.cpp
62 lines (50 loc) · 990 Bytes
/
stairs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <thread>
#include <mutex>
#include <condition_variable>
using namespace std;
template <typename T>
void print_vector(vector<T> const &v)
{
cout << "[";
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
cout << ", ";
cout << *it;
}
cout << "]";
}
template <typename T>
void print_vector2(vector<vector<T>> const &v)
{
cout << "[";
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
cout << ", ";
print_vector(*it);
}
cout << "]" << endl;
}
class Solution {
public:
int climbStairs(int n) {
long long a=1, b=1;
long long t;
while(n--) {
t = b;
b = b + a;
a = t;
}
return a;
}
};
int main() {
Solution s;
int output = s.climbStairs(45);
cout << output << endl;
return 0;
}