Simple 4 Line C++ Solution


  • 0

    class Solution {
    public:
    vector<int> constructRectangle(int area){
    int i = (int)sqrt(area); // get the mid point
    while(area % i != 0) --i; // subtract from mid point
    vector<int> result = {area/i, i}; // construct the vector

        return result;
    }
    

    };


Log in to reply
 

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