✅ 문제
https://school.programmers.co.kr/learn/courses/30/lessons/388351
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
✅ 코드
class Solution {
// hhmm 형식의 정수를 분 단위로 바꿔주는 헬퍼
private int toMinutes(int hhmm) {
int hour = hhmm / 100;
int minute = hhmm % 100;
return hour * 60 + minute;
}
public int solution(int[] schedules, int[][] timelogs, int startday) {
int answer = 0;
int n = schedules.length;
for (int i = 0; i < n; i++) {
int hopeTimeMinutes = toMinutes(schedules[i]);
int allowedLimit = hopeTimeMinutes + 10; // 희망 시각 + 10분
boolean eligible = true;
// 이벤트 7일차 순회
for (int j = 0; j < 7; j++) {
// 현재 날의 요일 계산: startday가 1=월 ... 7=일
int dayOfWeek = ((startday - 1 + j) % 7) + 1;
if (dayOfWeek == 6 || dayOfWeek == 7) {
// 토/일은 건너뛴다.
continue;
}
int actualTimeMinutes = toMinutes(timelogs[i][j]);
if (actualTimeMinutes > allowedLimit) {
// 지각한 날이 하나라도 있으면 탈락
eligible = false;
break;
}
}
if (eligible) answer++;
}
return answer;
}
}'Algorithm' 카테고리의 다른 글
| [JAVA 알고리즘] 지폐 접기 (0) | 2025.08.21 |
|---|---|
| [JAVA 알고리즘] 바탕화면 정리 (3) | 2025.08.14 |
| [JAVA 알고리즘] 폰켓몬 (5) | 2025.08.07 |
| [알고리즘] 기본 정렬 알고리즘 (Sorting Algorithms) (4) | 2025.08.06 |
| [SQL 알고리즘] FrontEnd 개발자 찾기 (3) | 2025.07.31 |