Skip to content

Instantly share code, notes, and snippets.

@davethomas11
Created November 3, 2015 06:09
Show Gist options
  • Save davethomas11/80ea90328557adc0deb5 to your computer and use it in GitHub Desktop.
Save davethomas11/80ea90328557adc0deb5 to your computer and use it in GitHub Desktop.
int solution(int A[], int N) {
int i = 0;
int * array = calloc(N + 1, sizeof(int));
int sum = N * (N + 1) / 2;
int sum2 = 0;
for (; i < N; i++) {
if (A[i] <= N && A[i] > 0 && array[A[i]] == 0) {
array[A[i]] = 1;
sum2 += A[i];
}
}
free(array);
return sum == sum2 ? 1 : 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment