程式語言 - LeetCode - C - 1431. Kids With the Greatest Number of Candies



參考資訊:
https://leetcode.com/studyplan/leetcode-75/

題目:


解答:

bool* kidsWithCandies(int* candies, int candiesSize, int extraCandies, int* returnSize)
{
    int cc = 0;
    int max = 0;
    bool *r = malloc(sizeof(bool) * candiesSize);

    for (cc = 0; cc < candiesSize; cc++) {
        if (candies[cc] > max) {
            max = candies[cc];
        }
        r[cc] = false;
    }

    *returnSize = candiesSize;
    for (cc = 0; cc < candiesSize; cc++) {
        if ((candies[cc] + extraCandies) >= max) {
            r[cc] = true;
        }
    }

    return r;
}