Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. static Long fibonacci(int m){
  2. if(m < 0) {
  3. throw new IllegalArgumentException("index must be >= 0");
  4. }
  5.  
  6. Long[] arr = new Long[m+1];
  7.  
  8. //TODO uzyć lambdy
  9.  
  10. BiFunction<Integer, Long[], Long> fun = (n, memo) ->{
  11. if(memo[n] != null){
  12. return memo[n];
  13. } else {
  14. Long val;
  15. if(n > 1){
  16. val = Main.fun.apply(n-1, memo) + Main.fun.apply(n-2, memo);
  17. }
  18. else {
  19. val = 1L;
  20. }
  21. memo[n] = val;
  22. return val;
  23. }
  24. };
  25.  
  26. return fun.apply(m, arr);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement