Skip to content

Commit a3b4482

Browse files
authored
Create Solution.c
1 parent f63987e commit a3b4482

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
int firstMissingPositive(int* nums, int numsSize) {
2+
3+
int Max = nums[0], i, *Count;
4+
5+
for(i = 1; i<numsSize; i++){
6+
Max = (Max < nums[i]) ? nums[i] : Max;
7+
}
8+
9+
Count = (int*)calloc(Max+1, sizeof(int));
10+
for(i = 0; i<numsSize; i++){
11+
if(nums[i] > 0){
12+
Count[nums[i]]++;
13+
}
14+
}
15+
16+
i = 1;
17+
while(Count[i] != 0){
18+
i++;
19+
}
20+
21+
return i;
22+
}

0 commit comments

Comments
 (0)