Lesson4 - MaxCounters

score:66%
※The submission is being evaluated.で評価画面表れず。

作成日:2018/3/28
MaxCounters coding task - Learn to Code - Codility

// 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 {

    public static int[] solution(int N, int[] A) {
        // write your code in Java SE 8
        int maxnum = 0;
        int[] inc = new int[N];

        for(int i = 0; i < A.length; i++) {
            if(A[i] <= 0) {
                // none
            } else if(A[i] < N) {
                if ( ++inc[A[i]-1] > maxnum) {
                  maxnum = inc[A[i]-1];
                };
            } else if(A[i] == (N+1)) {
                for(int num = 0; num < inc.length; num++) {
                    inc[num] = maxnum;
                }
            } else {
                // none
            }
        }
        return inc;
    }
}