Skip to content
Open

meh #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/io/zipcoder/Problem2.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package io.zipcoder;

import java.util.ArrayList;

public class Problem2 {
// public static int fib(int n) {
// if (n <= 1) return n;
// return fib(n - 1) + fib(n - 2);
// }
ArrayList<Integer> list = new ArrayList<>(13);
public String fibonaccilIteration(int n) {

list.add(0);
list.add(1);
if (list.size() - 1 < n) {
for (int i = 0; i < list.size(); i++) {
list.add(i + 2, list.get(i) + list.get(i + 1));
}
}
System.out.println(list);
return list.toString();
}
}
11 changes: 11 additions & 0 deletions src/test/java/io/zipcoder/Problem2Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;

public class Problem2Test {
Problem2 problem2 = new Problem2();
@Test
public void testFibonaccilIteration(){
String expected = "0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144";
String actual = problem2.fibonaccilIteration(150);
Assert.assertEquals(expected,actual);
}

}