From 31c44f4839a8695ce6b59391d7c1cc7e16d66305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D=7CMinseok=20Kim?= Date: Wed, 1 May 2024 23:04:32 +0900 Subject: [PATCH] =?UTF-8?q?23=EC=B0=A8=EC=8B=9C=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=84=A0=EC=A0=95=20=EB=B0=8F=20solved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\235\230-\352\260\234\354\210\230.swift" | 2 +- alstjr7437/README.md | 3 +- ...353\241\234\354\204\270\354\212\244.swift" | 29 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 "alstjr7437/\355\201\220/\355\224\204\353\241\234\354\204\270\354\212\244.swift" 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 c14fbc2..de373e4 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -22,4 +22,5 @@ | 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 | \ 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