Guest User

Untitled

a guest
Apr 30th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // you can also use imports, for example:
  2. // import java.util.*;
  3.  
  4. // you can write to stdout for debugging purposes, e.g.
  5. // System.out.println("this is a debug message");
  6.  
  7. class Solution {
  8. int maxElement = 0;
  9. public int[] solution(int N, int[] A) {
  10. int[] result = new int[N];
  11. for(int i = 0; i < A.length; i++) {
  12. if(A[i] >= 1 && A[i] <= N) {
  13. result = increase(A[i], result);
  14. maxElement = Math.max(result[A[i]-1], maxElement);
  15. } else if (A[i] == N + 1) {
  16. maxCounter(result);
  17. }
  18. }
  19. return result;
  20. }
  21. public int[] increase(int i, int[] j) {
  22. j[i-1] += 1;
  23. return j;
  24. }
  25.  
  26. public int[] maxCounter(int[] j) {
  27. for(int z = 0; z < j.length; z++) {
  28. j[z] = maxElement;
  29. }
  30. return j;
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment