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
- 운영체제의 분류
- this()와 참조변수 this 차이점
- 이것이코딩테스트다
- 호출스택
- 프로그래머스
- 인스턴스 메서드
- static import문
- this()
- 오버라이딩과 오버로딩 차이점
- 운영체제란 무엇인가
- 기본형 매개변수
- static 메서드
- PriorityQueue
- 조상의 생성자
- 운영체제의 예
- stateful widget
- webview_flutter
- stateless widget
- 객체 배열
- 오버로딩
- 초기화 순서
- 참조형 매개변수
- object클래스
- 명예의전당(1)
- stateful widget 생명주기
- 참조형 반환타입
- 클래스 변수
- FLUTTER
- 운영체제의 목적
- 운영체제의 구조
Archives
- Today
- Total
Coram Deo
[프로그래머스] Lv1. 최소 직사각형 본문
1. 나의 코드
class Solution {
public int solution(int[][] sizes) {
// 최소 직사각형
// 가로와 세로 둘중 더 긴 길이를 가로에 넣는다.
// 가로 중 가장 긴 길이 * 세로 중 가장 긴 길이
int answer = 0;
for(int i=0; i<sizes.length; i++){
if(sizes[i][0] < sizes[i][1]){
int tmp = sizes[i][0];
sizes[i][0] = sizes[i][1];
sizes[i][1] = tmp;
}
}
int maxW = sizes[0][0];
int maxH = sizes[0][1];
for(int j=0; j<sizes.length; j++){
if(sizes[j][0] > maxW){
maxW = sizes[j][0];
}
if(sizes[j][1] > maxH){
maxH = sizes[j][1];
}
}
answer = maxW * maxH;
return answer;
}
}
2. Math.max를 사용한 코드
class Solution {
public int solution(int[][] sizes) {
int answer = 0;
int maxW = 0;
int maxH = 0;
for(int[] card : sizes){
maxW = Math.max(maxW, Math.max(card[0], card[1]));
maxH = Math.max(maxH, Math.min(card[0], card[1]));
}
answer = maxW * maxH;
return answer;
}
}
'알고리즘 공부' 카테고리의 다른 글
[프로그래머스] Lv1. 문자열 내 마음대로 정렬하기 (0) | 2024.08.30 |
---|---|
[프로그래머스] Lv1. K번째 수 (0) | 2024.08.30 |
[프로그래머스] JadenCase 문자열 만들기(Java) - 리팩토링 과정 (0) | 2024.07.09 |
[백준] 1427. 소트인사이드 (0) | 2024.06.24 |
[프로그래머스] - 명예의 전당 (1) (LinkedList 사용) (0) | 2024.06.18 |