[Swift 알고리즘] 프린터

https://programmers.co.kr/learn/courses/30/lessons/42587

func solution2(_ priorities:[Int], _ location:Int) -> Int {
    
    var ready = priorities
    var answer = 0
    var index = location
    
    
    while true {
        
        if ready.first == ready.max() {
            ready.removeFirst()
            answer += 1
            if index == 0 {
                break
            } else {
                index -= 1
                
            }
        } else {
            let temp = ready.removeFirst()
            ready.append(temp)
            
            if index == 0 {
                index = ready.count - 1
                
            } else {
                index -= 1
            }
            
        }
    }
    
    return answer
    
}

좋은 웹페이지 즐겨찾기