Jam's story
[최소직사각형] 본문
- 왼쪽을 두 변중에 제일 큰 변이 오도록설정하고,
- 왼쪽변들중에 제일 큰변, 오른쪽변들중에 제일 큰변을 구해서 둘이 곱해서 반환
package soltest;
public class Solution11 {
public static int solution(int[][] sizes) {
int answer = 0;
int maxi=0,maxj=0;
//왼쪽을 제일큰수로 설정하기
for (int i = 0; i < sizes.length; i++) {
int temp=0;
if(sizes[i][0]<sizes[i][1]) {
temp=sizes[i][0];
sizes[i][0]=sizes[i][1];
sizes[i][1]=temp;
}
}
for (int i = 0; i < sizes.length; i++) {
if(maxi<sizes[i][0]) maxi=sizes[i][0];
if(maxj<sizes[i][1]) maxj=sizes[i][1];
}
//System.out.println(maxi+","+maxj);
answer=maxi*maxj;
//System.out.println(answer);
return answer;
}
public static void main(String[] args) {
int[][] sizes= {{60, 50}, {30, 70}, {60, 30} ,{80, 40}};
solution(sizes);
}
}
// 0,0 0,1
/* 0.0 [[60, 50],
* 1,0[30, 70],
* 2,0[60, 30],
* 3,0 [80, 40]] */
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 다트게임 (0) | 2022.07.07 |
---|---|
[프로그래머스] 가운데 글자 가져오기 (0) | 2022.07.05 |
[프로그래머스] 2016년 (0) | 2022.06.30 |
[프로그래머스 ] 두 개 뽑아서 더하기 (0) | 2022.06.29 |
[예산] (0) | 2022.06.28 |
Comments