Python 풀이
from itertools import combinations
def prime(data):
for j in range(2, int(data ** 0.5) + 1):
if data % j == 0:
return False
return True
def solution(nums):
com = list(combinations(nums, 3))
result = 0
for i in com:
if prime(sum(i)):
result += 1
return result
Java 풀이
class Solution {
public int solution(int[] nums) {
int count = 0;
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
for (int k = j + 1; k < nums.length; k++) {
if (Prime(nums[i] + nums[j] + nums[k])) {
count++;
}
}
}
}
return count;
}
public static boolean Prime(int data) {
boolean result = true;
for (int i = 2; i < data; i++) {
if (data % i == 0) {
result = false;
break;
}
}
return result;
}
}