-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path70-climbing-stairs.cpp
More file actions
41 lines (35 loc) · 938 Bytes
/
Copy path70-climbing-stairs.cpp
File metadata and controls
41 lines (35 loc) · 938 Bytes
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
#include <iomanip>
#include <chrono>
#include <iostream>
using namespace std;
class Solution {
public:
// first attempt
int climbStairs(int n) {
int res;
if(n==1)
res=1;
else if(n==2)
res=2;
else {
int i=2, n2=1, n1=2;
while(++i<=n) {
res=n1+n2;
n2=n1;
n1=res;
}
}
return res;
}
};
int main() {
Solution solution;
int x;
cin >> x;
auto t1 = chrono::high_resolution_clock::now();
cout << solution.climbStairs(x) << '\n';
auto t2 = chrono::high_resolution_clock::now();
chrono::duration<double, milli> ms_double = t2 - t1;
cout << setprecision(17) << ms_double.count() << " ms\n";
return 0;
}