import java.util.*;
class Solution {
public int[] solution(String[] wallpaper) {
int[] answer = new int[4];
//파일이 있는 위치의 x,y 값을 각각 리스트에 담기
List<Integer> xList = new ArrayList<>();
List<Integer> yList = new ArrayList<>();
for(int i=0; i<wallpaper.length; i++){
for(int j=0; j<wallpaper[0].length(); j++){
if(wallpaper[i].charAt(j)=='#'){
xList.add(i);
yList.add(j);
}
}
}
// 왼쪽 위끝점(minX, minY) ~ 오른쪽 아래끝점(maxX, maxY) 드래그
int minX = Collections.min(xList);
int minY = Collections.min(yList);
int maxX = Collections.max(xList);
int maxY = Collections.max(yList);
answer[0] = minX;
answer[1] = minY;
answer[2] = maxX +1;
answer[3] = maxY +1;
return answer;
}
}
: 내가 짰지만 정말 핵구린걸 ~~
import java.util.*;
class Solution {
public int[] solution(String today, String[] terms, String[] privacies) {
List<Integer> answerList = new ArrayList<>();
Map<String, Integer> termsMap = new HashMap<>();
//약관 종류별 유효 기간 구하기
for(int i=0; i<terms.length; i++){
String[] term = terms[i].split(" ");
termsMap.put(term[0], Integer.parseInt(term[1]));
}
//각각의 유효기간을 구한다.
for(int i=0; i<privacies.length; i++){
//개인정보가 수집된 날짜, 약관 종류
String[] arr = privacies[i].split(" ");
//개인정보가 수집된 날짜의 년, 월, 일
int[] date = Arrays.stream(arr[0].split("\\."))
.mapToInt(Integer::parseInt)
.toArray();
int yyyy = date[0];
int mm = date[1];
int dd = date[2];
//약관 종류별로 유효기간 구하기
Integer value = termsMap.get(arr[1]);
int year = value/12;
value = value%12;
yyyy += year;
mm += value;
while(mm > 12){
yyyy++;
mm -=12;
}
dd--;
if(dd==0){
mm--;
dd = 28;
if(mm==0){
mm =12;
yyyy--;
}
}
//오늘 날짜와 유효기간을 비교하여, 파기할 것은 정답 리스트에 넣는다.
int[] todayArr = Arrays.stream(today.split("\\."))
.mapToInt(Integer::parseInt)
.toArray();
if(yyyy > todayArr[0]){
continue;
}
if(yyyy < todayArr[0]){
answerList.add(i+1);
continue;
}
if(mm < todayArr[1] || (mm == todayArr[1] && dd < todayArr[2])){
answerList.add(i+1);
}
}
return answerList.stream().mapToInt(i->i).toArray();
}
}