Ad

Java CoE
First code challenge 2023

import java.util.HashMap;
import java.util.Map;

public class Fibonacci {
	private static Map<Integer, Long> memoizationMap = new HashMap<>();

	public static long calcFibo(int n) {
		if (n <= 1) {
			return n;
		}

		if (memoizationMap.containsKey(n)) {
			return memoizationMap.get(n);
		}

		long fiboValue = calcFibo(n - 1) + calcFibo(n - 2);
		memoizationMap.put(n, fiboValue);

		return fiboValue;
	}
}