Commit 0f7a00e1 authored by Fokion Zervoudakis's avatar Fokion Zervoudakis

Simplify memoization.

parent e98debcd
......@@ -29,13 +29,10 @@ class DpFib {
*/
@Memoization
int fib(int n) {
if (M.containsKey(n)) {
return M.get(n);
} else {
int f = (n < 2) ? n : fib(n - 1) + fib(n - 2);
M.put(n, f);
return f;
if (!M.containsKey(n)) {
M.put(n, (n < 2) ? n : fib(n - 1) + fib(n - 2));
}
return M.get(n);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment