mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-03 19:03:28 +08:00
Update
This commit is contained in:
33
algorithm_interview_course/chapter_two/section_6.cpp
Normal file
33
algorithm_interview_course/chapter_two/section_6.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
int fibonacci_2(int i) {
|
||||
if(i <= 0) return 0;
|
||||
if(i == 1) return 1;
|
||||
return fibonacci_2(i - 1) + fibonacci_2(i - 2);
|
||||
}
|
||||
void time_consumption() {
|
||||
int n;
|
||||
while (cin >> n) {
|
||||
milliseconds start_time = duration_cast<milliseconds >(
|
||||
system_clock::now().time_since_epoch()
|
||||
);
|
||||
|
||||
fibonacci_2(n);
|
||||
|
||||
milliseconds end_time = duration_cast<milliseconds >(
|
||||
system_clock::now().time_since_epoch()
|
||||
);
|
||||
cout << milliseconds(end_time).count() - milliseconds(start_time).count()
|
||||
<<" ms"<< endl;
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
time_consumption();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user