-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path이중우선순위큐.swift
More file actions
39 lines (33 loc) · 906 Bytes
/
이중우선순위큐.swift
File metadata and controls
39 lines (33 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// 이중우선순위큐.swift
//
//
// Created by chihoooon on 2022/02/17.
//
import Foundation
func solution(_ operations:[String]) -> [Int] {
var priorityQueue: [Int] = []
for operation in operations {
let command = operation.components(separatedBy: " ")
switch command[0] {
case "I":
priorityQueue.append(Int(command[1])!)
priorityQueue.sort(by: >)
case "D":
if !priorityQueue.isEmpty {
if command[1] == "-1" {
priorityQueue.removeLast()
}
else {
priorityQueue.removeFirst()
}
}
default:
break
}
}
if priorityQueue.isEmpty {
return [0, 0]
}
return [priorityQueue.max()!, priorityQueue.min()!]
}