diff --git "a/alstjr7437/BFS/\354\227\260\352\262\260-\354\232\224\354\206\214\354\235\230-\352\260\234\354\210\230.swift" "b/alstjr7437/BFS/\354\227\260\352\262\260-\354\232\224\354\206\214\354\235\230-\352\260\234\354\210\230.swift" index 9a4bcd1..0f8b99b 100644 --- "a/alstjr7437/BFS/\354\227\260\352\262\260-\354\232\224\354\206\214\354\235\230-\352\260\234\354\210\230.swift" +++ "b/alstjr7437/BFS/\354\227\260\352\262\260-\354\232\224\354\206\214\354\235\230-\352\260\234\354\210\230.swift" @@ -41,4 +41,4 @@ for i in 1...n{ } } -print(result) +print(result) \ No newline at end of file diff --git a/alstjr7437/README.md b/alstjr7437/README.md index 4f2d3ef..253921c 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -21,6 +21,7 @@ | 17차시 | 2024.03.16 | DP | 구간 나누기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/61 | | 18차시 | 2024.03.23 | 다익스트라 | 최단 경로 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/66 | | 19차시 | 2024.03.27 | 문자열 | IOIOI | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/67 | -| 20차시 | 2024.04.03 | BFS | 숨바꼭질 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 | +| 22차시 | 2024.04.13 | BFS | 연결 요소의 개수 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 | | 21차시 | 2024.04.06 | 비트마스킹 | 집합 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/74 | -| 22차시 | 2024.04.13 | BFS | 연결 요소의 개수 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 | \ No newline at end of file +| 22차시 | 2024.04.13 | BFS | 연결 요소의 개수 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 | +| 23차시 | 2024.05.01 | 큐 | 프로세스 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/79 | \ No newline at end of file diff --git "a/alstjr7437/\355\201\220/\355\224\204\353\241\234\354\204\270\354\212\244.swift" "b/alstjr7437/\355\201\220/\355\224\204\353\241\234\354\204\270\354\212\244.swift" new file mode 100644 index 0000000..d94a798 --- /dev/null +++ "b/alstjr7437/\355\201\220/\355\224\204\353\241\234\354\204\270\354\212\244.swift" @@ -0,0 +1,29 @@ +import Foundation + +func solution(_ priorities:[Int], _ location:Int) -> Int { + var result = 0 + var priorities = priorities + var location = location + + while priorities.count != 0 { + location -= 1 + let p_max = priorities.max()! + let temp = priorities[0] + if p_max != temp { // max가 아닐 경우(빼야할 경우가 아닌 경우) + priorities.append(temp) // 뒤에 넣기 + priorities.removeFirst() // 처음꺼 빼기 + if location < 0 { // location이 음수면 제일 뒤에서 부터 + location = priorities.count - 1 + } + } else { // max일 경우(빼야할 경우) + priorities.removeFirst() + result += 1 + if location < 0 { // location이 적절하게 오면 멈추기 + break + } + } + + } + + return result +} \ No newline at end of file