C++ 5 lines solution


  • 0
        vector<int> constructRectangle(int area) {
            int s=sqrt(area),width=s,length=s;
            while(width*length!=area) 
                if(width*length<area) length++; 
                else if(width*length>area) width--;
            return {length,width};
        }
    

Log in to reply
 

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