Created
January 26, 2018 05:23
-
-
Save clarkdo/da4e020353a9e5f99456a74aba884079 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int[] solution(int N, int[] A) { | |
int[] result = new int[N]; | |
int currentMax = 0; | |
int max = 0; | |
for (int i: A) { | |
if (i == N + 1) { | |
max = currentMax; | |
} else { | |
int digit = result[i-1]; | |
result[i-1] = digit = max > digit ? max + 1 : digit + 1 ; | |
if (currentMax < digit) { | |
currentMax = digit; | |
} | |
} | |
} | |
for(int i = 0; i < result.length; i++) { | |
if(result[i] < max) { | |
result[i] = max; | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment