Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Long fibonacci(int m){
- if(m < 0) {
- throw new IllegalArgumentException("index must be >= 0");
- }
- Long[] arr = new Long[m+1];
- //TODO uzyć lambdy
- BiFunction<Integer, Long[], Long> fun = (n, memo) ->{
- if(memo[n] != null){
- return memo[n];
- } else {
- Long val;
- if(n > 1){
- val = Main.fun.apply(n-1, memo) + Main.fun.apply(n-2, memo);
- }
- else {
- val = 1L;
- }
- memo[n] = val;
- return val;
- }
- };
- return fun.apply(m, arr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement