LeetCode "492. Construct the Rectangle"
2017-01-24 11:05
495 查看
Idea is, among all factors of the int, we pick the two that is the closest pair. And searching from sqrt(area) is a better idea:
https://discuss.leetcode.com/topic/76314/3-line-clean-and-easy-understand-solution
https://discuss.leetcode.com/topic/76314/3-line-clean-and-easy-understand-solution
class Solution { public: vector<int> constructRectangle(int area) { //defactor vector<int> ret; if(area<1) return ret; int i = 1; while(i <= area) { if(area % i == 0) { int a = i; int b = area /i; if(a>b) break; if(a==b) return {a,b}; ret = {b, a}; } i++; } return ret; } };
相关文章推荐
- [LeetCode]492. Construct the Rectangle
- LeetCode 492 Construct the Rectangle
- leetcode 492. Construct the Rectangle
- 【算法作业2】LeetCode 492. Construct the Rectangle
- LeetCode:492. Construct the Rectangle
- LeetCode刷题 | 492. Construct the Rectangle
- LeetCode-492. Construct the Rectangle
- [LeetCode]492. Construct the Rectangle(构造矩形)
- LeetCode 492. Construct the Rectangle(Java)
- leetcode 492. Construct the Rectangle
- leetcode-492-Construct the Rectangle
- LeetCode - 492. Construct the Rectangle
- leetcode 492. Construct the Rectangle
- leetcode 492 Construct the Rectangle
- python--leetcode 492. Construct the Rectangle
- leetcode 492. Construct the Rectangle(easy)
- 【Leetcode】492. Construct the Rectangle
- LeetCode-492. Construct the Rectangle (Java)
- LeetCode 492. Construct the Rectangle (算法)
- leetcode 492. Construct the Rectangle