Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: None  |  size: 0.33 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Solution {
  2. public static int fibonacci(int n) {
  3.    int[] table = new int[n + 1];
  4.    for (int i = 0; i < table.length; i++) {
  5.       if (i == 0) {
  6.          table[i] = 0;
  7.       } else if (i == 1) {
  8.          table[i] = 1;
  9.       } else {
  10.          table[i] = table[i - 2] + table[i - 1];
  11.       }
  12.    }
  13.  
  14.    return table[n];
  15. }
  16.  
  17. }