https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
public int[] solution(String today, String[] terms, String[] privacies) {
List<Integer> answer = new ArrayList<>();
String[] strings = today.split("\\.");
int todaySum =
Integer.parseInt(strings[0]) * 12 * 28 + Integer.parseInt(strings[1]) * 28 + Integer.parseInt(
strings[2]);
Map<String, Integer> mapTerms = new HashMap<>();
for (int i = 0; i < terms.length; i++) {
String[] string = terms[i].split(" ");
mapTerms.put(string[0], Integer.parseInt(string[1]) * 28);
}
for (int i = 0; i < privacies.length; i++) {
String[] string = privacies[i].split(" ");
String[] integers = string[0].split("\\.");
int sum =
Integer.parseInt(integers[0]) * 12 * 28 + Integer.parseInt(integers[1]) * 28 + Integer.parseInt(
integers[2]);
if (sum + mapTerms.get(string[1]) <= todaySum) {
answer.add(i + 1);
}
}
Collections.sort(answer);
int[] arr = answer.stream()
.mapToInt(Integer::intValue)
.toArray();
return arr;
}
📍포인트
1. 날짜 계산을 어떻게할지 판단하기
2. map 사용.
3. List to Array
📍삽질
1. 처음 코드는 쓸모없는 map을 하나 더 만들어서 순서가 보장되지 않게되어 추가되는 배열이 이상했음.
2. List to Array 방법이 기억이 안 났음.
'코딩테스트' 카테고리의 다른 글
[코딩테스트(Java)] 프로그래머스 72411 메뉴 리뉴얼 (0) | 2025.03.20 |
---|---|
[코딩테스트(Java)] 프로그래머스 118666 성격 유형 검사하기 (0) | 2025.03.16 |
[코딩테스트(Java)] 프로그래머스 67256 키패드 누르기 (0) | 2025.03.15 |
[코딩테스트(Java)] 프로그래머스 64061 크레인 인형뽑기 게임 (0) | 2025.03.14 |
[코딩테스트(Java)] 프로그래머스 81301 숫자 문자열과 영단어 (0) | 2025.03.13 |