SW Test/Programmers

[Programmers] Lv1.둜또의 졜고 μˆœμœ„μ™€ μ΅œμ € μˆœμœ„(kotlin)

An effort will never betray 😎 2022. 7. 22. 23:54
λ°˜μ‘ν˜•

문제

https://school.programmers.co.kr/learn/courses/30/lessons/77484?language=kotlin

 

 

μ˜ˆμ‹œ

https://school.programmers.co.kr/learn/courses/30/lessons/77484?language=kotlin

 

 

 

풀이

  • λͺ¨λ“  μˆœμœ„λŠ” μΌμΉ˜ν•˜λŠ” 숫자λ₯Ό κ΅¬ν•˜μ—¬ 7-(숫자) λ₯Ό ν•˜λ©΄ ꡬ할 수 μžˆμŠ΅λ‹ˆλ‹€.
  • μ£Όμ˜ν•  점은 7μ΄λΌλŠ” λ“±μˆ˜λŠ” μ—†κΈ° λ•Œλ¬Έμ— 7이 λ‚˜μ˜¬ κ²½μš°μ— 6등을 λ°˜ν™˜ν•  수 μžˆλ„λ‘ μ˜ˆμ™Έμ²˜λ¦¬λ§Œ ν•΄μ£Όμ‹œλ©΄ λ©λ‹ˆλ‹€.
class Solution {
    fun solution(lottos: IntArray, win_nums: IntArray): IntArray {
        return intArrayOf(
            (7-win_nums.filter{it in lottos}.size - lottos.count{it == 0}).let{
                if(it > 6) 6 else it    
            },
            (7-win_nums.filter{it in lottos}.size).let{
                if(it > 6) 6 else it
            }
        )
    }
}

 

 

 

μ°Έκ³ 

  • ν•¨μˆ˜ν˜• ν”„λ‘œκ·Έλž˜λ° 언어인 kotlin의 νŠΉμ„±μ— 맞게 ν•¨μˆ˜λ₯Ό 많이 읡히자 😽
λ°˜μ‘ν˜•