我有两个数组,我需要进行排序并找到两个数组中出现的最小数字。如果没有平等,那么它应该返回-1
,如果存在相等性,那么它应该返回该数字。如何在两个数组中找到共同的最小数字
这里是我的我有到目前为止的代码
public int solution(int[] A, int[] B)
{
int minA = A.Min();// Get minimum number of array A
int minB = B.Min();// Get minimum number of array B
if (minA == minB)// If both arrays have the same smallest number
return minA;
else
return -1;
}
问题是,它只是检查的最低数量的平等,如果它不匹配,那么它将返回。我如何才能看到下一个最低的数字?
不错,比我的伪代码更干净。相等比较应该是==,While循环应该循环<而不是<=长度(基于零的索引)。 – PeteB
谢谢。更正了代码! – forayer