function fibonacci(N) {
if (N <= 2) {
return 1;
}

let a = 1; // N - 2
let b = 1; // N - 1
let result;

for (let i = 3; i <= N; i++) {
result = a + b;
a = b;
b = result;
}

return result;
}


'IT General' 카테고리의 다른 글

Codility #3-PermMissingElem  (0) 2018.08.18
Codility #3-FrogJmp  (0) 2018.08.18
Codility #2-OddOccurrencesInArray  (0) 2018.08.18
Codility #2-CyclicRotation  (0) 2018.08.18
Codility #1-BinaryGap  (0) 2018.08.15

+ Recent posts