Construct the Rectangle Leetcode

Given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:

You need to output the length L and the width W of the web page you designed in sequence.

Example:

 

Note:
  1. The given area won’t exceed 10,000,000 and is a positive integer
  2. The web page’s width and length you designed must be positive integers.

Solution

According to the requirement 3 difference between L and W should be as small as possible. That is why we will start with the square-root of the area. 

Next : Java interview question Binary Tree Path


References
https://leetcode.com/problems/construct-the-rectangle/

Leave a Reply