Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 29, 2018 07:13
Show Gist options
  • Save clarkdo/421fce4bc31ee96fa05bd4a712e320a7 to your computer and use it in GitHub Desktop.
Save clarkdo/421fce4bc31ee96fa05bd4a712e320a7 to your computer and use it in GitHub Desktop.
class Solution {
public int solution(int[] A) {
int length = A.length;
boolean[] appearance = new boolean[length];
int count = 0;
for (int i : A) {
int position = i-1;
if (i <= length && !appearance[position]) {
appearance[position] = true;
count++;
}
}
return count == length ? 1 : 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment