-
[Programmers] 프린터STUDYING/Algorithm 2021. 9. 27. 00:40728x90
https://programmers.co.kr/learn/courses/30/lessons/42587
import Foundation func solution(_ priorities:[Int], _ location:Int) -> Int { var pq: [(Int, Int)] = [] var res = 0 for i in 0..<priorities.count { pq.append((priorities[i], i)) } var cnt = 0 while !pq.isEmpty { let pqFirstPriority = (pq.first?.0)! var isBig = true for i in 0..<pq.count { if pqFirstPriority < pq[i].0 { isBig = false } } if !isBig { let pqFirst = pq.first! pq.removeFirst() pq.append(pqFirst) } else { cnt += 1 if pq.first?.1 == location { break; } pq.removeFirst() } } return cnt }
'STUDYING > Algorithm' 카테고리의 다른 글
[Programmers] 두 개 뽑아서 더하기 (0) 2021.09.27 [Programmers] 가장 큰 수 (0) 2021.09.27 [Programmers] 실패율 (0) 2021.09.27 [Programmers] 가장 먼 노드 (0) 2021.09.27 [Programmers] 타겟 넘버 (0) 2021.09.27