https://school.programmers.co.kr/learn/courses/30/lessons/42628
문제 링크
import Foundation
func solution(_ operations:[String]) -> [Int] {
var queue = [Int]()
for i in operations {
let a = i.split(separator: " ").map{String($0)}
let f = a[0]
let s = a[1]
if f == "D" {
if s == "-1" {
let min = queue.min()
for (index, value) in queue.enumerated() {
if min == value {
queue.remove(at: index)
}
}
} else {
let max = queue.max()
for (index, value) in queue.enumerated() {
if max == value {
queue.remove(at: index)
}
}
}
} else {
queue.append(Int(s)!)
}
print(queue)
}
return [Int(queue.max() ?? 0), Int(queue.min() ?? 0)]
}