Skip to content

Commit 198277f

Browse files
committed
chaged Fibonacci Optimized
1 parent 016d94f commit 198277f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/main/java/com/thealgorithms/recursion/FibonacciOptimized.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
FIBONACCI 0 1 1 2 3 5 8 13 21 34 55 ...
88
*/
99

10-
/*T his is optimized solution for fibonacci series. It computes fibonacci series in linear(O(n)) time complexity */
11-
10+
/* This is optimized solution for fibonacci series. It computes fibonacci series in linear (O(n)) time complexity */
1211
public final class FibonacciOptimized {
13-
static int fibonacci(int limit, int num1, int num2){
14-
if(limit==1){
12+
13+
private FibonacciOptimized() {
14+
// Prevent instantiation
15+
}
16+
17+
static int fibonacci(int limit, int num1, int num2) {
18+
if (limit == 1) {
1519
return num1;
16-
}
17-
else{
18-
return fibonacci(limit-1, num2, num1+num2);
20+
} else {
21+
return fibonacci(limit - 1, num2, num1 + num2);
1922
}
2023
}
21-
22-
}
23-
24+
}

0 commit comments

Comments
 (0)