Given two arrays that have only positive values. It is necessary to return the minimum value that is in both arrays. For example:
А{3,2,5,6,4} B{9,7,2,3,1,5} That is, in this example, the minimum value will be 2.
I wrote this code here:
public static int solution(int[] A, int[] B) { int min = A[0]; for(int i=1; i<A.length; i++) { if(min > A[i]) { min = A[i]; } } for(int j=0; j<B.length; j++) { if(min == B[j]) { System.out.println(min); } } System.out.println(min); return min; } I know that it does not work as it should, but I do not know how to finish it. May need recursion?