Last active
June 15, 2017 20:34
-
-
Save vdenotaris/703fccc31cfd3181e3f4cd8377379062 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.HashSet; | |
import java.util.Set; | |
class Solution { | |
private static int max(int[] A) { | |
int max = A[0]; | |
for (int i = 1; i < A.length; i++) | |
if (A[i] > max) | |
max = A[i]; | |
return max; | |
} | |
public int solution(int[] A) { | |
Set < Integer > setA = new HashSet < Integer > (); | |
for (int i = 0; i < A.length; i++) | |
setA.add(A[i]); | |
return (A.length == setA.size() && this.max(A) == A.length) ? 1 : 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment