문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
알고리즘
- 반복문을 통해 기능을 개발시킨다.
- 개발되는 매 순간 진도가 100 이상이 되면 기능들을 배포하고 배포한 값을 answer에 추가한다.
코드
class Solution {
fun solution(progresses: IntArray, speeds: IntArray): IntArray {
var answer = mutableListOf<Int>()
val progressesCopy = progresses.toMutableList()
val speedsCopy = speeds.toMutableList()
while (progressesCopy.size != 0){
speedsCopy.forEachIndexed { idx, e ->
progressesCopy[idx] += e
}
var cnt = 0
while (progressesCopy[0] >= 100){
progressesCopy.removeAt(0)
speedsCopy.removeAt(0)
cnt++
if (progressesCopy.size == 0){
break
}
}
if (cnt > 0){
answer.add(cnt)
}
}
return answer.toIntArray()
}
}
github
GitHub - junjange/KotlinAlgorithm: 내가 푼 코딩 테스트 문제와 해결법(Kotlin)
내가 푼 코딩 테스트 문제와 해결법(Kotlin). Contribute to junjange/KotlinAlgorithm development by creating an account on GitHub.
github.com
'CodingTest > Programers' 카테고리의 다른 글
[programers] 프로그래머스(파이썬) : 내적 (0) | 2022.09.21 |
---|---|
[programers] 프로그래머스(파이썬) : 정수 삼각형 (0) | 2022.09.18 |
[programers] 프로그래머스(코틀린) : 없는 숫자 더하기 (0) | 2022.09.07 |
[programers] 프로그래머스(파이썬) : 없는 숫자 더하기 (0) | 2022.09.07 |
[programers] 프로그래머스(파이썬) : 성격 유형 검사하기 (1) | 2022.09.04 |