【leetcode】和为零的N个唯一整数

 

int* sumZero(int n, int* returnSize){
    int* arr= (int*)calloc(n,sizeof(int));
    int i,pst=0;
    for (i=1; i<=n/2; i++)
    {
        arr[pst++]=i;
        arr[pst++]=-i;
    }
    *returnSize = (n%2)? pst+1: pst;
    return arr;

}

 

posted @ 2020-09-29 14:45  温暖了寂寞  阅读(123)  评论(0编辑  收藏  举报