Skip to content

[Algorithm] ParkingBillย #158

@hwangJi-dev

Description

@hwangJi-dev

๐Ÿ’ฌย ๋ฌธ์ œ

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/

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions