C++ clean solution


  • 0
    Z
    class Solution {
    public:
        vector<int> constructRectangle(int area) {
            int a = sqrt(area), b = a;
            for(; ;) {
                if(a * b < area)    ++a;
                else if(a * b > area)    --b;
                else break;
            }
            return vector<int>{a, b};
        }
    };
    

Log in to reply
 

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