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;
- int currentMax = 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) {
- increase(A[i], result);
- maxElement = Math.max(result[A[i]-1], maxElement);
- } else if (A[i] == N + 1) {
- currnetMax = maxElement;
- }
- }
- for(int i = 0; i < result.length; i++) {
- result[i] = Math.max(result[i], currentMax);
- }
- return result;
- }
- public void increase(int i, int[] j) {
- j[i-1] = currentMax + j[i-1] + 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment