728x90
반응형
1. 피자 나눠 먹기 (1)
class Solution {
public int solution(int n) {
int answer = 0;
if( n % 7 == 0 ){
answer = n / 7;
} else {
answer = n / 7 + 1;
}
return answer;
}
}
2. 피자 나눠 먹기 (2)
class Solution {
public int solution(int n) {
int answer = 0;
for(int i=1; i<=n; i++){
if(( 6 * i ) % n == 0) {
answer = i ;
break;
}
}
return answer;
}
}
3. 피자 나눠 먹기 (3)
class Solution {
public int solution(int slice, int n) {
int answer = 0;
for(int i=1; i<= n * slice; i++){
if( slice * i >= n ){
answer = i;
break;
}
}
return answer;
}
}
4. 배열의 평균값
class Solution {
public double solution(int[] numbers) {
double answer = 0;
double sum = 0;
for(int i=0; i<numbers.length; i++){
sum += numbers[i];
}
answer = sum / numbers.length;
return answer;
}
}
728x90
반응형
'study_IT > 알고리즘 노트' 카테고리의 다른 글
[programmers] Lv2. 최댓값과 최솟값 (0) | 2023.10.20 |
---|---|
[programmers] 코딩테스트 입문 Day 5 (0) | 2023.10.17 |
알고리즘 복잡도 (Complexity) (0) | 2023.10.14 |
[programmers] 코딩테스트 입문 Day 3 (0) | 2023.10.12 |
[programmers] 코딩테스트 입문 Day 2 (1) | 2023.10.10 |