[JAVA 문제 풀이] 259. 최소직사각형

프로그래머스 (86491)
Stupefyee's avatar
May 16, 2025
[JAVA 문제 풀이] 259. 최소직사각형
notion image
 

내가 작성한 코드

class Solution { public int solution(int[][] sizes) { int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < sizes.length; i++) { // 둘중에 큰 값은 가로, 작은 값은 세로로 정렬 int width = Math.max(sizes[i][0], sizes[i][1]); int height = Math.min(sizes[i][0], sizes[i][1]); // 큰 값을 각 max값에 저장 if (maxWidth < width) { maxWidth = width; } if (maxHeight < height) { maxHeight = height; } } return maxWidth * maxHeight; } }
 

다른 사람의 코드

class Solution { public int solution(int[][] sizes) { int length = 0, height = 0; for (int[] card : sizes) { length = Math.max(length, Math.max(card[0], card[1])); height = Math.max(height, Math.min(card[0], card[1])); } return length * height; } }
  • 더 압축하기
 
Share article

stupefyee