유연근무제

하이솝·2026년 3월 6일

(2026.02.25)

(timelogs[i][j] > limit && (day != 6 || day != 7))
limit = limit + 100 + (limit % 100 - 60);와 같이
원래 구현하려던 코드와 다르게 작성하는 문제 발생
알고리즘을 구현할 때 더 생각하고 작성하는 습관 필요

소요 시간: 39분 46초

내가 제출한 정답

class Solution {
    public int solution(int[] schedules, int[][] timelogs, int startday) {
        int answer = 0;
        int limit; // 출근 제한 시간
        int[] success = new int[schedules.length];
        for (int i = 0; i < timelogs.length; i++) {
            limit = schedules[i] + 10;
            if (limit % 100 >= 60) {
                limit = (limit - limit % 100) + 100 + (limit % 100 - 60);
            }
            int day = startday;
            boolean flag = true;
            for (int j = 0; j < timelogs[i].length; j++) {
                if (timelogs[i][j] > limit && !(day == 6 || day == 7)) {
                    success[i] = 0;
                    flag = false;
                    break;
                }
                day++;
                if (day > 7) {
                    day = 1;
                }
            }
            if (flag == true) {
                success[i] = 1;
            }
        }
        // 성공한 인원 수 세기
        for (int i = 0; i < success.length; i++) {
            if (success[i] == 1) {
                answer++;    
            }
        }
        return answer;
    }
}
  • limit 계산식을 더 간단하게 변경
  • day가 6 또는 7일때 넘어가기 추가 (조건문 변경)
  • success배열 삭제 후 바로 answer 증가

AI를 이용한 수정/보완

class Solution {
    public int solution(int[] schedules, int[][] timelogs, int startday) {
        int answer = 0;
        int limit; // 출근 제한 시간
        int[] success = new int[schedules.length];
        for (int i = 0; i < timelogs.length; i++) {
            limit = schedules[i] + 10;
            if (limit % 100 >= 60) {
                limit += 40;
            }
            boolean isSuccess = true;
            for (int j = 0; j < timelogs[i].length; j++) {
                int day = (startday + j - 1) % 7 + 1;
                if (day == 6 || day == 7) {
                    continue;
                }
                if (timelogs[i][j] > limit) {
                    isSuccess = false;
                    break;
                }
            }
            if (isSuccess == true) {
                answer++;
            }
        }        
        return answer;
    }
}

0개의 댓글