payal-kothari
7/24/2017 - 10:01 PM

From https://leetcode.com/problems/construct-the-rectangle/#/description

public class Solution {
    public int[] constructRectangle(int area) {
        int[] ans = {0,0};
        
        int start = (int) Math.sqrt(area) ;
        
        while (area % start != 0){
            start--;
        }
        
        ans[0] =  (area / start > start) ? area / start : start;
        ans[1] =  (area / start > start) ? start : area / start;
        
        return ans;
    }
}