-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
๐ฌย ๋ฌธ์
https://app.codility.com/programmers/trainings/5/parking_bill/
๐ฌย Idea
์ด ์ฃผ์ฐจ ์๊ฐ์ ๊ณ์ฐํ ๋ค ์ ์ฅ๋ฃ 2 + ์ฒซ ์ฃผ์ฐจ์๊ฐ 3 + ์ดํ ์ฃผ์ฐจ์๊ฐ์ด ์๋ค๋ฉด 4๋ฅผ ๊ณฑํ์ฌ ๋ฐํํ๋ค.
๐ฌย ํ์ด
public func solution(_ E : inout String, _ L : inout String) -> Int {
let e = E.components(separatedBy: ":").map({ Int($0)! })
let l = L.components(separatedBy: ":").map({ Int($0)! })
let startHour = e[0]
let startMinute = e[1]
let endHour = l[0]
let endMinute = l[1]
var time = 0
if startHour < endHour {
if startMinute > 0 {
time += 60 - startMinute
} else {
time += 60
}
time += (endHour - startHour - 1) * 60 + endMinute
} else {
time += endMinute
}
if time == 0 {
return 2
} else if time <= 60 {
return 5
} else {
return 2 + 3 + ((time - 60) / 60) * 4 + (time % 60 > 0 ? 4 : 0)
}
}
**์์์๊ฐ**
:
ํ๊ฐํ
: https://app.codility.com/demo/results/trainingVQ8V2M-BCQ/