본문 바로가기
(문제풀이)

프로그래머스(java) : 피자 나눠 먹기(3)

by cogito-new 2022. 10. 9.

class Solution {
    public int solution(int slice, int n) {
        int answer = 0;
        int cut;
        //피자 조각이 적은 경우 피자 개수 up
        if(slice < n) {
            cut = n/slice;
            if(cut*slice >= n) {
                answer = cut;
            } else {
                answer = cut +1;
            }
            
        } else {
            answer = 1;
        } 
        
        return answer;
    }
}
반응형