beat 100%,C++ solution


  • 0
    H

    first i sqrt the area, the min must less than the root

    class Solution {
    public:
        vector<int> constructRectangle(int area) {
            int n = sqrt(area);
            int min = n;
            int max = n;
            while(area%min != 0 ){
                min--;
            }
            max = area/min;
            return vector<int>{max,min};
        }
    };
    

Log in to reply
 

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