Skip to content

[Algorithm] 롤케이크 자르기 #42

Description

@hwangJi-dev

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

import Foundation
func solution(_ topping:[Int])->Int{vartops=Array(repeating:0, count: topping.max()! +1)foriin topping {tops[i]+=1}varpointer=0varq1=Set(topping).count
varq2:Set<Int>=[]varans=0while pointer <= topping.count -1{letct=topping[pointer]tops[ct]-=1iftops[ct]==0{
q1 -=1}
q2.insert(ct)if q1 == q2.count {
ans +=1}
pointer +=1}return ans
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions