
😎풀이
- 분 단위로 변환
- 두 시간의 차이 확인
60, 15, 5, 1순으로 탐색하며 변환
- 변환에 필요한 횟수 반환
function convertTime(current: string, correct: string): number {
const curMin = convertMin(current)
const corMin = convertMin(correct)
let gap = corMin - curMin
let count = 0
if(gap >= 60) {
count += Math.floor(gap / 60)
gap %= 60
}
if(gap >= 15) {
count += Math.floor(gap / 15)
gap %= 15
}
if(gap >= 5) {
count += Math.floor(gap / 5)
gap %= 5
}
if(gap >= 1) {
count += Math.floor(gap / 1)
gap %= 1
}
return count
};
function convertMin(time: string) {
const [hour, min] = time.split(":").map(Number)
return min + hour * 60
}