5ms Java solution


  • 0
    F
    public int[] constructRectangle(int area) {
        int W = (int) Math.floor(Math.sqrt(area));
        int L = area / W;
        
        while(L * W != area) {
            W--;
            L = area / W;
        }
        
        return new int[]{L, W};
    }

Log in to reply
 

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