피자나눠먹기1

Psj·3일 전
0

코딩테스트

목록 보기
22/30

내풀이

class Solution {
    public int solution(int n) {
        int piceOfPizza = 7;

        int answer = 0;

        if((n>piceOfPizza) && (n%piceOfPizza > 0)){
            answer = ((n/piceOfPizza)*piceOfPizza+piceOfPizza)/piceOfPizza;
        }else if((n>piceOfPizza) && (n%piceOfPizza == 0)){
            answer = (n/piceOfPizza);
        }else{
            answer = 1;
        }

        return answer;
    }
}

다른사람풀이1

class Solution {
    public int solution(int n) {
        return (n + 6) / 7;
    }
}

다른사람풀이2

class Solution {
    public int solution(int n) {
        int answer = (n%7==0) ? n/7 : n/7 + 1;

        return answer;
    }
}

이 문제를 다른사람들은 모두 int형으로 인해 피자한판 단위로 나뉘는것을 이용했다.

profile
Software Developer

0개의 댓글

관련 채용 정보