Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 코딩테스트
- array
- Math
- implement
- sorting
- hash table
- database
- 코테
- geometry
- Matrix
- Number Theory
- Data Structure
- two pointers
- 구현
- string
- simulation
- Class
- dynamic programming
- Tree
- greedy
- SQL
- Binary Search
- 파이썬
- Counting
- Method
- bit manipulation
- java
- Binary Tree
- Stack
- 자바
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 492. Construct the Rectangle 본문
1. Input
1) int area
2. Output
1) 넓이가 area인 직사각형을 만드는 [세로, 가로] int배열 중 다음 조건을 만족하는 것을 반환
- 세로 >= 가로
- 세로와 가로의 차는 가능한 작아야 한다.
3. Constraint
1) 1 <= area <= 10^7
4. Example
Input: area = 4 -> Output: [2,2]
Input: area = 37 -> Output: [37,1]
5. Code
1) 첫 코드(2023/02/26)
int[] answer = {area, 1};
for(int i=area-1 ; i>=(int)Math.sqrt(area) ; i--){
if(area%i==0){
if(Math.abs(answer[0]-answer[1]) > Math.abs(i-(area/i))){
answer[0] = i; answer[1] = area/i;
}
}
}
return answer;
- 다른 방법은 없을까..
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2574. Left and Right Sum Differences (0) | 2023.02.27 |
---|---|
[LeetCode/Easy] 496. Next Greater Element I (0) | 2023.02.26 |
[프로그래머스/Lv.1] 대충 만든 자판 (0) | 2023.02.23 |
[프로그래머스/Lv.2] 행렬의 곱셈 (0) | 2023.02.22 |
[LeetCode/Easy] 455. Assign Cookies (0) | 2023.02.22 |