We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💬 문제
https://school.programmers.co.kr/learn/courses/30/lessons/42627
💬 Idea
SJF(Shortest Job First) 알고리즘을 구현하는 문제이다.
→ 정렬을 통해서 우선순위가 높은 데이터를 배열의 끝으로 보내서 removeLast()를 수행하자.
💬 풀이
import Foundation func solution(jobs:[[Int]]) -> Int { var sortedJobs = jobs.sorted(by: { if $0[0] == $1[0] { return $0[1] > $1[1] } else { return $0[0] > $1[0] } }) var jobQueue: [[Int]] = [sortedJobs.removeLast()] var totalTime = 0 var time = jobQueue.first![0] while !jobQueue.isEmpty { let now = jobQueue.removeLast() totalTime += abs(time - now[0]) + now[1] time += now[1] while !sortedJobs.isEmpty && sortedJobs.last![0] <= time { jobQueue.append(sortedJobs.removeLast()) } jobQueue.sort(by: { $0[1] > $1[1] }) if jobQueue.isEmpty && !sortedJobs.isEmpty { jobQueue.append(sortedJobs.removeLast()) time += abs(time - jobQueue.last![0]) } } return totalTime / jobs.count }
The text was updated successfully, but these errors were encountered:
#195 - 디스크 컨트롤러 문제 풀이
cb5c957
hwangJi-dev
No branches or pull requests
💬 문제
https://school.programmers.co.kr/learn/courses/30/lessons/42627
💬 Idea
SJF(Shortest Job First) 알고리즘을 구현하는 문제이다.
→ 정렬을 통해서 우선순위가 높은 데이터를 배열의 끝으로 보내서 removeLast()를 수행하자.
💬 풀이
The text was updated successfully, but these errors were encountered: