【leetcode】492. 构造矩形

 

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* constructRectangle(int area, int* returnSize){
    int* arr = (int*)calloc(sizeof(int), 2);
    int w = sqrt(area), i;
    for(i=w; i>=1; i--){
        if(area%i == 0){
            arr[0]=area/i;
            arr[1]=i;
            break;
        }
    }
    *returnSize=2;
    return arr;
}

 

posted @ 2020-11-26 20:19  温暖了寂寞  阅读(49)  评论(0编辑  收藏  举报