Leetcode 1679. Max Number of K-Sum Pairs
version_1:
Runtime: 150 ms, faster than 89.17% of C online submissions for Max Number of K-Sum Pairs.
int compare(const void *a, const void *b){return *(int *)a - *(int *)b;}int maxOperations(int* nums, int numsSize, int k){qsort(nums, numsSize, sizeof(int), compare);if (numsSize == 1) return 0;int times = 0;int i = 0;int j = numsSize - 1;while(i < j){if(nums[i] + nums[j] == k){i++;j--;times++;}else if(nums[i] + nums[j] > k) j--;else i++;}return times;}