【leetcode】找出给定方程的正整数解

 

int** findSolution(int (*customFunction)(int, int), int z, int* returnSize, int** returnColumnSizes) {
    int** arr = (int**)calloc(z,sizeof(int*));
    *returnColumnSizes = (int*)calloc(z,sizeof(int));
    int i,j,pst=0;
    for (i=1; customFunction(i,1)<=z; i++)
    {
        for (j=1; customFunction(i,j)<=z; j++)
        {
            if (customFunction(i,j) == z)
            {
                (*returnColumnSizes)[pst]=2;
                arr[pst] = (int*)calloc(2,sizeof(int));
                arr[pst][0]=i;
                arr[pst++][1]=j;
            }
        }
    }
    *returnSize=pst;
    return arr;
}

 

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