CodingTest/Programers

[programers] 프로그래머스(코틀린) : 기능 개발

JunJangE 2022. 9. 8. 20:03

문제

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

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