티스토리 뷰
🔗 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/388351
💡 구현 아이디어
- 월~금요일 시간을 뽑아냄
- 시간 비교는 분단위로 진행
- 분단위 시간 = (표현된 시간 / 100 * 60) + (표현된 시간 % 100) = 시의 분 + 분
- 희망 시간이 실제 시간보다 작거나 같으면 통과, 크면 실패
- 한 사람에 대해 전체 통과하면 1 아니면 0
- 결과 반환
💻 코드
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
📌 풀이 또는 기억할 정보
'PS > 문제 풀이' 카테고리의 다른 글
| [프로그래머스/Swift] 172927번 - 광물 캐기 (0) | 2025.04.22 |
|---|---|
| [프로그래머스/Swift] 12946번 - 하노이의 탑 (0) | 2025.04.16 |
| [프로그래머스/Swift] 81302번 - 거리두기 확인하기 (0) | 2025.04.13 |
| [프로그래머스/Swift] 12905번 - 가장 큰 정사각형 찾기 (0) | 2025.04.11 |
| [프로그래머스/Swift] 147354번 - 테이블 해시 함수 (0) | 2025.04.10 |
