값의 조합이 존재하는지 여부를 확인하고 싶습니다. 아래 코드는 잘 작동하지만 비효율적입니다. 나는이 문제의 좋은 해결책을 찾고있다.조합 행
public static void main(String args[]) {
Integer data[] = {
1, 2, 5, 1, 9, 3, 5, 3, 2
};
Integer combination[] = {
1, 3 ,2
};
System.out.println("Result: " + combinations(data, combination));
}
public static boolean combinations(Integer dataset[], Integer combination[]) {
boolean results[] = new boolean[combination.length];
Integer count = 0;
for (Integer comb : combination) {
for (Integer data : dataset) {
if (data.equals(comb)) {
results[count++] = true;
break;
}
}
}
for (Boolean result : results) {
if (!result) {
return false;
}
}
return true;
}
강한 텍스트
... 다음과 같다() http://codereview.stackexchange.com/ –