leetcode[Construct the Rectangle]//待整理多种解法

来源:互联网 发布:javascript写网页 编辑:程序博客网 时间:2024/05/21 17:11

解法一:

public class Solution {    public int[] constructRectangle(int area) {        int length = (int) Math.ceil(Math.sqrt(area));//从平方根开始分界,求出长度的最大可能值        boolean isFind = true;        int[] res = new int[2];        while(isFind){        if(area % length == 0){        res[0] = length;        res[1] = area / length;        return res;        }        else{        length++;        }        }                return res;    }}


原创粉丝点击