Skip to content

Commit

Permalink
23차시 문제 선정 및 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
alstjr7437 committed May 1, 2024
1 parent 71ba4bf commit 31c44f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion alstjr7437/BFS/연결-요소의-개수.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ for i in 1...n{
}
}

print(result)
print(result)
3 changes: 2 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
| 18차시 | 2024.03.23 | 다익스트라 | <a href="https://www.acmicpc.net/problem/1753">최단 경로</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/66 |
| 19차시 | 2024.03.27 | 문자열 | <a href="https://www.acmicpc.net/problem/5525">IOIOI</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/67 |
| 20차시 | 2024.04.03 | BFS | <a href="https://www.acmicpc.net/problem/1697">숨바꼭질</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 |
| 22차시 | 2024.04.13 | BFS | <a href="https://www.acmicpc.net/problem/11724">연결 요소의 개수</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 |
| 22차시 | 2024.04.13 | BFS | <a href="https://www.acmicpc.net/problem/11724">연결 요소의 개수</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 |
| 23차시 | 2024.05.01 || <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42587">프로세스</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/79 |
29 changes: 29 additions & 0 deletions alstjr7437/큐/프로세스.swift
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 31c44f4

Please sign in to comment.