Advertisement
knyazer

Untitled

Apr 22nd, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5. public static int algo(int[] arr, int[] d, int index, int dmax) {
  6. if (index == arr.length) {
  7. return dmax + 1;
  8. }
  9.  
  10. if (arr[index] > arr[index - 1]) d[index] = dmax + 1;
  11. else d[index] = 0;
  12.  
  13. if (d[index] > d[index - 1]) dmax = d[index];
  14.  
  15. return algo(arr, d, index + 1, dmax);
  16. }
  17.  
  18. public static void main(String[] args) {
  19. int arr[] = {4, 5, 7, 2, 1, 13, 18};
  20. int d[] = new int[arr.length];
  21.  
  22. for (int i = 0; i < arr.length; i++) {
  23. d[i] = 0;
  24. }
  25.  
  26. System.out.println(algo(arr, d, 1, 0));
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement