완전 탐색
어려움 .. 개빡대갈 ..
최소 직사각형
class Solution {
public int solution(int[][] sizes) {
int max_v=0;
int max_h=0;
for (int i = 0; i<sizes.length; i++) {
int v=Math.max(sizes[i][0],sizes[i][1]);
int h=Math.min(sizes[i][0],sizes[i][1]);
max_v=Math.max(max_v,v);
max_h=Math.max(max_h,h);
}
return max_v * max_h;
}
}
모의고사
아래 정답에서 if-else 가 틀림
import java.util.*;
class Solution {
public int[] solution(int[] answers) {
int[] one = {1, 2, 3, 4, 5}; // 5
int[] two = {2, 1, 2, 3, 2, 4, 2, 5}; // 8
int[] thr = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; // 10
int on = 0;
int tw = 0;
int tr = 0;
for (int i = 0; i < answers.length; i++) {
int a = answers[i];
if (a == one[i % 5]) on++;
if (a == two[i % 8]) tw++;
if (a == thr[i % 10]) tr++;
}
int max = Math.max(on, Math.max(tw, tr));
List<Integer> l = new ArrayList<>();
if (on == max) l.add(1);
if (tw == max) l.add(2);
if (tr == max) l.add(3);
// if (on > tw) {
// if (on > tr) {
// l.add(1);
// }
// if (on == tr) {
// l.add(1);
// l.add(3);
// }
// } else if (tw > on) {
// if (tw > tr) {
// l.add(2);
// }
// if (tw == tr) {
// l.add(2);
// l.add(3);
// }
// } else {
// if (on > tr) {
// l.add(1);
// l.add(2);
// }
// if (on == tr) {
// l.add(1);
// l.add(2);
// l.add(3);
// }
// }
int[] arr = new int[l.size()];
// System.out.println(l.size());
for (int i = 0; i < l.size(); i++) {
arr[i] = l.get(i).intValue();
}
Arrays.sort(arr);
return arr;
}
}
import java.util.*;
class Solution {
public int[] solution(int[] answers) {
int[] one = {1, 2, 3, 4, 5}; // 5
int[] two = {2, 1, 2, 3, 2, 4, 2, 5}; // 8
int[] thr = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; // 10
int on = 0;
int tw = 0;
int tr = 0;
for (int i = 0; i < answers.length; i++) {
int a = answers[i];
if (a == one[i % 5]) on++;
if (a == two[i % 8]) tw++;
if (a == thr[i % 10]) tr++;
}
int max = Math.max(on, Math.max(tw, tr));
List<Integer> l = new ArrayList<>();
if (on == max) l.add(1);
if (tw == max) l.add(2);
if (tr == max) l.add(3);
int[] arr = new int[l.size()];
for (int i = 0; i < l.size(); i++) {
arr[i] = l.get(i).intValue();
}
Arrays.sort(arr);
return arr;
}
}
소수 찾기
카펫
피로도
전력망을 둘로 나누기
모음 사전
Last updated