public static int[] isthereDuplicates(int[] combination) {
Set<Integer> foundedNumbers = new HashSet<>();
for (int i= 0; index < combination.length; i++) {
if (foundedNumbers.contains(combination[i])) {
combination[i] -= 1;
} else {
foundedNumbers.add(combination[i]);
}
return combination;
}
我需要查找并替换数组数组中的重复项。数组数组也是随机选择1到40之间的7个数字。如果我有一个副本,但是当我有几个例如我有1,14,20,1,38,1,5时,我提出的代码是有效的。它会改变为中间1,但第二个1将保持不变。java阵列查找重复项并替换它们
为什么你定义一个HashSet的则从来没有使用它? ('nadjeniBrojevi') –
当您将变量名称翻译成英文(为什么首先不是英文?),那么请翻译所有变量名称。你的param和Set仍然需要翻译。 – Tom
您可以告诉我们您发布的输入(1,14,20,1,38,1,5),您要查找的结果是什么? –