leetcode492

public class Solution {
    public int[] ConstructRectangle(int area)
        {
            Dictionary<int, int> dic = new Dictionary<int, int>();

            for (int i = 1; i <= area; i++)
            {
                var W = i;
                var L = Convert.ToInt32(area / i);

                if (L >= W && W * L == area)
                {
                    dic.Add(L, W);
                }
            }

            var d = dic.LastOrDefault();
            var ary = new int[2] { d.Key, d.Value };
            Console.WriteLine("L=" + ary[0] + ",W=" + ary[1]);
            return ary;
        }
}

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

原文地址:https://www.cnblogs.com/asenyang/p/6732314.html