FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

package DynamicProgramming; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; /** * @author Varun Upadhyay (https://github.com/varunu28) */ public class Fibonacci { private static Map map = new HashMap(); public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); // Methods all returning [0, 1, 1, 2, 3, 5, ...] for n = [0, 1, 2, 3, 4, 5, ...] System.out.println(fibMemo(n)); System.out.println(fibBotUp(n)); } /** * This method finds the nth fibonacci number using memoization technique * * @param n The input n for which we have to determine the fibonacci number * Outputs the nth fibonacci number **/ private static int fibMemo(int n) { if (map.containsKey(n)) { return map.get(n); } int f; if (n

Back | FazBrowse Home | New Git URL