用java判断两个数组是否有相同的部分和public static boolean haveEqualSums(int[] input1, int[] input2) {
时间: 2024-06-06 12:10:54 浏览: 72
JS判断两个数组或对象是否相同的方法示例
5星 · 资源好评率100%
public static boolean haveEqualSums(int[] input1, int[] input2) {
int sum1 = 0, sum2 = 0;
for (int i = 0; i < input1.length; i++) {
sum1 += input1[i];
}
for (int i = 0; i < input2.length; i++) {
sum2 += input2[i];
}
if (sum1 == sum2) {
return true;
}
for (int i = 0; i < input1.length; i++) {
for (int j = 0; j < input2.length; j++) {
if (input1[i] == input2[j]) {
int temp1 = sum1 - input1[i] + input2[j];
int temp2 = sum2 - input2[j] + input1[i];
if (temp1 == temp2) {
return true;
}
}
}
}
return false;
}
阅读全文