230729 개인정보 수집 유효기간

Jongleee·2023년 7월 29일
0

TIL

목록 보기
324/737
 public int[] solution(String today, String[] terms, String[] privacies) {
	List<Integer> answer = new ArrayList<>();

	Map<String, Integer> expireDate = new HashMap<>();

	for (String term : terms) {
		String type = term.split(" ")[0];
		int date = Integer.parseInt(term.split(" ")[1]);
		expireDate.put(type, date);
	}

	int todayInt = Integer.parseInt(today.replace(".", ""));

	for (int i = 0; i < privacies.length; i++) {
		String privacy = privacies[i];
		int date = Integer.parseInt(privacy.split(" ")[0].replace(".", ""));
		String type = privacy.split(" ")[1];

		int year = date / 10000;
		int month = (date % 10000) / 100;
		int day = date % 100;

		month += expireDate.get(type);
		day -= 1;

		if (day == 0) {
			month -= 1;
			day += 28;
		}
		if (month > 12) {
			year += (month / 12);
			month = month - 12 * (month / 12);
		}
		if (month == 0) {
			month = 12;
			year -= 1;
		}

		date = year * 10000 + month * 100 + day;

		if (date < todayInt) {
			answer.add(i);
		}
	}

	int[] answerArr = new int[answer.size()];

	for (int i = 0; i < answer.size(); i++) {
		answerArr[i] = answer.get(i) + 1;
	}

	return answerArr;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/150370

0개의 댓글