티스토리 뷰

🔗 문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/388351

💡 구현 아이디어

  1. 월~금요일 시간을 뽑아냄
  2. 시간 비교는 분단위로 진행
  3. 분단위 시간 = (표현된 시간 / 100 * 60) + (표현된 시간 % 100) = 시의 분 + 분
  4. 희망 시간이 실제 시간보다 작거나 같으면 통과, 크면 실패
  5. 한 사람에 대해 전체 통과하면 1 아니면 0
  6. 결과 반환

💻 코드

import Foundation

func solution(_ schedules:[Int], _ timelogs:[[Int]], _ startday:Int) -> Int {
    var result: Int = 0
    var logs: [[Int]] = []
    
   
    for i in 0..<timelogs.count {
        var idx = (8 - startday) % 7
        var temp: [Int] = []
        
        for _ in 0..<5 {
            temp.append(timelogs[i][idx])
            idx += 1
            if idx == 7 { idx = 0 }
        }
        
        logs.append(temp)
    }
    
    for idx in 0..<schedules.count {
        result += check(hope: schedules[idx], reals: logs[idx])
    }
    
    return result
}

func check(hope: Int, reals: [Int]) -> Int {
    let total = (hope / 100 * 60) + (hope % 100) + 10 // 분으로 통일
    
    for real in reals {
        let compReal = (real / 100 * 60) + (real % 100)
        // 출근한 시간이 희망한 시간보다 늦으면
        if total < compReal {
            return 0
        }
    }
    return 1
}

❌ 틀린 이유 및 틀린 부분

⏳ 시간 복잡도

O(N * M) = 사람수 * 5일 = (최대) 1000 * 5 = 5000

📌 풀이 또는 기억할 정보

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함