TIL #68

loci·2024년 7월 7일
0

TIL

목록 보기
65/103


개미 군단
5,3,1 을 빼는 경우들로 0을 만드는 카운트를 리턴


나의코드

class Solution {
    fun solution(hp: Int): Int {
        var answer: Int = 0
        var temp = hp
        while(temp > 0){
            if(temp - 5 >= 0){
                temp -= 5
                answer++
            }else if(temp - 3 >= 0){
                temp -= 3
                answer++
            }else if(temp - 1 >= 0){
                temp -= 1
                answer++
            }
        }
        return answer
    }
}

다른사람풀이

class Solution {
    fun solution(hp: Int) = hp / 5 + hp % 5 / 3 + hp % 5 % 3
}

profile
편리한 개발자

0개의 댓글