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

xiaoxiao2021-02-28  109

解法一:

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; } }

转载请注明原文地址: https://www.6miu.com/read-67863.html

最新回复(0)