This commit is contained in:
2025-09-29 10:56:06 +08:00
parent f6e998beff
commit af0fe8a168
3 changed files with 103 additions and 0 deletions

27
src/976.c Normal file
View File

@@ -0,0 +1,27 @@
#include <solution/976.h>
#include <stdlib.h>
int cmp(const void *a, const void *b)
{
return *(const int *)b - *(const int *)a;
}
int largestPerimeter(int *nums, int numsSize)
{
qsort(nums, numsSize, sizeof(int), cmp);
int i = 0, j = 1;
while (i < numsSize - 2 && j < numsSize - 1)
{
int k = j + 1;
if (nums[i] < nums[j] + nums[k])
return nums[i] + nums[j] + nums[k];
else
{
j++;
i++;
}
}
return 0;
}