codility 刷题 MaxCounters

      int B[] = new int[N];

        int max =0;
        int base =0; //不要顺滑去set数组,记住基准值就好
        for (int i =0 ;i < A.length; i++) {
            if (A[i] == N +1 ) {
                base =max;
            } else {

               int currValue =    (B[A[i]-1] > base? B[A[i]-1]:base   )   +1;
                B[A[i]-1] =currValue;
                if(currValue > max) {
                    max = currValue;
                }
            }
        }

        for(int i =0; i< B.length ;i++) {
            if(B[i] < base) {
                B[i] =base;
            }
        }

        return B;

 

你可能感兴趣的:(codility)