[C] Simple C solution


  • 0
    P

    Start with sqrt(area) is a intuitive solution.
    It's really simple to implement and more efficient than brute-force.

    int* constructRectangle(int area, int* returnSize) {
        int L, W=(int)sqrt(area)/1;
        int *res;
    
        while(W>1 && area%W!=0)
            W--;
    
        L=area/W;
    
        res = (int*)malloc(sizeof(int)*2);
        res[0] = L;
        res[1] = W;
        *returnSize=2;
        return res;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.