程式語言 - LeetCode - C++ - 492. Construct the Rectangle



題目:


解答:

class Solution {
public:
    vector<int> constructRectangle(int area) {
        int w = sqrt(area);

        while (area % w) {
            w -= 1;
        }

        return { area / w, w };
    }
};