程式語言 - LeetCode - C - 1207. Unique Number of Occurrences



題目:


解答:

bool uniqueOccurrences(int* arr, int arrSize)
{
    #define MAX_HASH_SIZE 2000

    int c0 = 0;
    int chk[MAX_HASH_SIZE] = { 0 };
    int hash[MAX_HASH_SIZE] = { 0 };

    for (c0 = 0; c0 < arrSize; c0++) {
        hash[1000 + arr[c0]] += 1;
    }

    for (c0 = 0; c0 < MAX_HASH_SIZE; c0++) {
        if (hash[c0] && chk[hash[c0]]) {
            return false;
        }
        chk[hash[c0]] = 1;
    }

    return true;
}