Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created February 15, 2021 18:44
Show Gist options
  • Save MohammedALREAI/5bb82989d1f205fd2542fbe32c028549 to your computer and use it in GitHub Desktop.
Save MohammedALREAI/5bb82989d1f205fd2542fbe32c028549 to your computer and use it in GitHub Desktop.
509. Fibonacci Number lettcode
function fib(n: number): number {
const arr = [1, 1];
let counter = 3;
while (counter <= n) {
const nextFib = arr[0] + arr[1];
arr[0] = arr[1];
arr[1] = nextFib;
counter++;
}
return n< 1 ? 0: n===1? 1: arr[1]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment