Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Poll
- lastIndex
- contentToString
- Developer
- 2020
- booleanarray
- PriorityQueue
- hackerrank
- programmers
- 2D Array
- Util
- solution
- GREEDY
- 알고리즘
- foreach
- 코틀린
- sortedBy
- report
- indices
- 프로그래머스
- Kotlin
- Queue
- dynamic programming
- heap
- intarray
- Recursion
- 동적계획법
- dp
- Java
- Main
Archives
- Today
- Total
Code in
프로그래머스 큐 기능개발 with Kotlin 본문
프로그래머스 큐 기능개발 문제입니다.
IntelliJ에서의 문제 풀이입니다.
var progresses: IntArray = intArrayOf(93,30,55) // 진도가 변하므로 var 사용
val speeds: IntArray = intArrayOf(1, 30, 5) // 속도가 일정하므로 val 사용
fun solution(progresses: IntArray, speeds: IntArray): IntArray {
var answer = intArrayOf() // int Array 형식으로 초기화
var cnt = 100 // 가장 오래 걸리더라도 100일 이하
var front = 0 // 큐에서 Data가 사라지는 방향
var tmp: Int // Int 형식으로 선언
while (cnt > 0 && front < progresses.size){
cnt-- // 하루가 지남
tmp = 0 // 하루에 완료된 일 기록
for (i in front until progresses.size){
progresses[i] += speeds[i] // 하루동안 진행도 증가
}
while (front < progresses.size && progresses[front] >= 100){
front++ // 진행도가 100이 넘어서 데이터 삭제
tmp++ // 데이터가 삭제된 횟수 = 하루에 완료된 일 개수
}
if (tmp != 0) // 0일 경우 Pass
answer += tmp // 하루에 완료된 일의 개수가 Array의 요소로 추가됨.
}
return answer
}
fun main() {
print(solution(progresses, speeds).contentToString()) // 2, 1
}
URL: https://programmers.co.kr/learn/courses/30/lessons/42586?language=kotlin
코딩테스트 연습 - 기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 ��
programmers.co.kr
'알고리즘 스터디_문제풀이' 카테고리의 다른 글
프로그래머스 큐 프린터 with Kotlin (0) | 2020.08.11 |
---|---|
프로그래머스 큐 다리를 지나는 트럭 with Kotlin (0) | 2020.08.11 |
프로그래머스 정렬 H-Index with Kotlin (0) | 2020.08.10 |
프로그래머스 정렬 가장 큰 수 with Kotlin (3) | 2020.08.10 |
프로그래머스 정렬 K번째 수 문제풀이 with Kotlin (0) | 2020.08.10 |
Comments