Created
November 3, 2015 06:09
-
-
Save davethomas11/80ea90328557adc0deb5 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
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