https://leetcode.com/problems/construct-the-rectangle/submissions/
그냥 질문 그대로 구현했다.
좀 느릴 것 같다.
class Solution {
public int[] constructRectangle(int area) {
int value[] = new int[2];
if(area == 0){
value[0] = 0;
value[1] = 0;
return value;
}
else if(area == 1){
value[0] = 1;
value[1] = 1;
return value;
}
int difference = area;
int start = 1;
int end = area;
int a, b;
for(int i = start; i <= end; i++){
if(area % i == 0){
a = i;
b = area / i;
if((a >= b)&&((a-b)<difference)){
difference = value[0] - value[1];
value[0] = a;
value[1] = b;
}
}
}
return value;
}
}
'Algorithm > LeetCode 문제 풀이' 카테고리의 다른 글
[LeetCode 130. Surrounded Regions] C++, Java (0) | 2019.04.09 |
---|---|
[LeetCode 200. Number of Islands] C++ , C++로 전향하기로 결정했다. (0) | 2019.04.03 |
[LeetCode 485] python - 예외 처리에 주의하기.. (0) | 2019.04.02 |
[LeetCode 283] python 리스트(큐/스택) 이용하기 (0) | 2019.04.02 |
[LeetCode 232, 283, 290 - 완료, 485, 492] python (0) | 2019.03.31 |