본문 바로가기
코딩테스트

프로그래머스 '로또의 최고 순위와 최저 순위' 코테풀이

by 생각스택 2025. 2. 26.
반응형

프로그래머스에서

레벨 1, 코틀린 언어, 정답률이 높은 순서대로 코테를 풀고 있습니다.

이번 문제는 '로또의 초고 순위와 최저 순위'입니다.

사이트 : https://school.programmers.co.kr/learn/challenges?order=acceptance_desc&levels=1&languages=kotlin&page=3

 

코딩테스트 연습 | 프로그래머스 스쿨

개발자 취업의 필수 관문 코딩테스트를 철저하게 연습하고 대비할 수 있는 문제를 총망라! 프로그래머스에서 선발한 문제로 유형을 파악하고 실력을 업그레이드해 보세요!

school.programmers.co.kr

위의 사이트에 들어가서

3페이지에서 내리시다보면

문제를 만나실 수 있습니다.

제 풀이 이렇습니다.

궁금하신 점이나 더 나은 풀이가 있으시면 댓글로 알려주세요

읽어 주셔서 감사합니다.

class Solution {
    fun solution(lottos: IntArray, win_nums: IntArray): IntArray {
        var answer: IntArray = intArrayOf()
        var worstCount = 0
        var bestCount = 0
        var randomCount = 0
        lottos.map { e -> if(e == 0){
            randomCount++
        }}
        bestCount += randomCount
        for(ele in win_nums){
            if(lottos.contains(ele)){
                worstCount++
                bestCount++
            }
        }
        if(worstCount == 0){
            worstCount = 1
        }
        if(bestCount == 0){
            bestCount = 1
        }
        answer = intArrayOf(7-bestCount, 7-worstCount)
        return answer
    }
}
반응형