Skip to content

Instantly share code, notes, and snippets.

@vdenotaris
Last active June 15, 2017 20:34
Show Gist options
  • Save vdenotaris/703fccc31cfd3181e3f4cd8377379062 to your computer and use it in GitHub Desktop.
Save vdenotaris/703fccc31cfd3181e3f4cd8377379062 to your computer and use it in GitHub Desktop.
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