CodingTest
코딩테스트 입문 - Day 11
Jiwon_Loopy
2025. 4. 20. 15:56
반응형
주사위의 개수
class Solution {
public int solution(int[] box, int n) {
int a = box[0] / n;
int b = box[1] / n;
int c = box[2] / n;
return a * b * c;
}
}
합성 수 찾기
import java.util.*;
class Solution {
public int solution(int n) {
int answer = 0;
ArrayList<Integer> arr = new ArrayList<>();
for(int i = 2; i<=n;i++){
for(int j = 2; j<=n;j++){
if(i*j > n){
break;
}
if(!arr.contains(i*j)){
arr.add(i*j);
}
}
}
return arr.size();
}
}
최댓값 만들기 (1)
import java.util.*;
class Solution {
public int solution(int[] numbers) {
Arrays.sort(numbers);
return numbers[numbers.length -1] * numbers[numbers.length -2];
}
}
팩토리얼
class Solution {
public int solution(int n) {
int fact = 1;
for(int i = 2; i<=10;i++){
fact *= i;
if(fact > n){
return i-1;
}
}
return 10;
}
}
728x90
반응형