Construct the Rectangle
来源:互联网 发布:安卓app推荐 知乎 编辑:程序博客网 时间:2024/06/07 22:41
题目:https://leetcode.com/submissions/detail/99862054/
先找到平方根,再用类似二分法的方式查找遍历,得到最优解。
vector<int> constructRectangle(int area) { vector<int> res; int w = sqrt(area); if(w*w == area) { res.push_back(w); res.push_back(w); return res; } int l = w+1; while(w>=1 && l<=area) { int tmp = w*l; if(tmp == area) { res.push_back(l); res.push_back(w); return res; } if(tmp > area) { w--; } else { l++; } } return res; }
0 0
- LeetCode_492. Construct the Rectangle
- LEETCODE--Construct the Rectangle
- Construct the Rectangle
- leetcode492: Construct the Rectangle
- 492. Construct the Rectangle
- 【leetcode】Construct the Rectangle
- 492. Construct the Rectangle
- LeetCode:Construct the Rectangle
- 492. Construct the Rectangle
- 492. Construct the Rectangle
- 492. Construct the Rectangle
- LeetCode Construct the Rectangle
- Construct the Rectangle
- 492. Construct the Rectangle
- Construct the Rectangle
- Construct the Rectangle
- 492. Construct the Rectangle
- 492. Construct the Rectangle
- Ubuntu14.04 编译 Android4.4.4
- easyui datagrid loadFilter loadData
- Java学习之数组操作
- flex amcharts demo
- 根据ip获取城市
- Construct the Rectangle
- flex amcharts line demo2
- CentOS6.8安装rabbitmq
- 几个颜色16进制
- PHP new staic() 和 new self()的区别
- 转载
- flex 多个站点弹出层 (替代infowindow)
- LeetCode (3)Longest Substring Without Repeating Characters
- eclipse中特殊的注释——TODO、FIXME和XXX的说明