-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fibonacci demo #22
base: main
Are you sure you want to change the base?
fibonacci demo #22
Conversation
// TODO | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implement this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested:
function fibonacci(int n) { | |
// TODO | |
} | |
function fibonacci(int n) { | |
if (n < 2) { | |
return n; | |
} | |
return fibonacci(n - 1) + fibonacci(n - 2); | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement this function in O(n) time complexity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested:
function fibonacci(int n) { | |
// TODO | |
} | |
function fibonacci(int n) { | |
if (n <= 1) { | |
return n; | |
} | |
var a = 0; | |
var b = 1; | |
var c = 0; | |
for (var i = 2; i <= n; i++) { | |
c = a + b; | |
a = b; | |
b = c; | |
} | |
return c; | |
} | |
No description provided.