给你一个整数 n,请你返回 任意 一个由 n 个 各不相同 的整数组成的数组,并且这 n 个数相加和为 0 。
in a mess.
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* sumZero(int n, int* returnSize){
    *returnSize = n;
    int *a = malloc(sizeof(int) * n);
    int max = n / 2;
    int cnt = max;
    for (int i = 0; i < cnt; i++) {
        a[i * 2] = max;
        a[i * 2 + 1] = 0 - max;
        max --;
    }
    if (n % 2 == 1) a[n - 1] = 0;
    return a;
}LeetCode - 和为零的N个唯一整数(No.1304)
原文:https://www.cnblogs.com/litun/p/12127859.html