Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // you can also use imports, for example:
- // import java.util.*;
- // you can write to stdout for debugging purposes, e.g.
- // System.out.println("this is a debug message");
- class Solution {
- int maxElement = 0;
- public int[] solution(int N, int[] A) {
- int[] result = new int[N];
- for(int i = 0; i < A.length; i++) {
- if(A[i] >= 1 && A[i] <= N) {
- result = increase(A[i], result);
- maxElement = Math.max(result[A[i]-1], maxElement);
- } else if (A[i] == N + 1) {
- maxCounter(result);
- }
- }
- return result;
- }
- public int[] increase(int i, int[] j) {
- j[i-1] += 1;
- return j;
- }
- public int[] maxCounter(int[] j) {
- for(int z = 0; z < j.length; z++) {
- j[z] = maxElement;
- }
- return j;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment