https://school.programmers.co.kr/learn/courses/30/lessons/86491
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
# 초기 코드
class Solution {
public int solution(int[][] sizes) {
int max_w = 0;
int max_h = 0;
for (int[] card : sizes) {
// 세로 길이가 더 길면 눕힘
if (card[0] < card[1]) {
int temp = card[0];
card[0] = card[1];
card[1] = temp;
}
if (max_w < card[0]) {
max_w = card[0];
}
if (max_h < card[1]) {
max_h = card[1];
}
}
return max_w * max_h;
}
}
- 카드 하나하나 눕히는 딩초코드 ┌( ´_ゝ` )┐
# ✨ 프로그래머스 1등 코드 ✨
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]));
}
int answer = length * height;
return answer;
}
}
- 문제의 난이도와 상관없이 동일한 코드를 간결하게 짜는 분들이 정말 실력자신 것 같다.
- 효간코짜의 길은 멀고도 험해 ~~~~~~~~
'코딩테스트 > 자바 문제풀이' 카테고리의 다른 글
[프로그래머스: 완전탐색] 소수 찾기 (0) | 2025.04.24 |
---|---|
[프로그래머스: 완전탐색] 모의고사 (0) | 2025.04.24 |
[프로그래머스: 해시] 완주하지 못한 선수 (1) | 2025.04.24 |
[프로그래머스: BFS] 단어 변환 (0) | 2025.04.24 |
[프로그래머스: DFS/BFS] 네트워크 (0) | 2025.04.23 |