Depuis qu'il est avéré être utile, je vais le poster comme une réponse. Peut-être que quelqu'un l'utilisera aussi.
Voici la réponse: http://www.geeksforgeeks.org/union-and-intersection-of-two-sorted-arrays-2/
Et par exemple à partir du lien:
// Java program to find intersection of
// two sorted arrays
class FindIntersection
{
/* Function prints Intersection of arr1[] and arr2[]
m is the number of elements in arr1[]
n is the number of elements in arr2[] */
static void printIntersection(int arr1[], int arr2[], int m, int n)
{
int i = 0, j = 0;
while (i < m && j < n)
{
if (arr1[i] < arr2[j])
i++;
else if (arr2[j] < arr1[i])
j++;
else
{
System.out.print(arr2[j++]+" ");
i++;
}
}
}
public static void main(String args[])
{
int arr1[] = {1, 2, 4, 5, 6};
int arr2[] = {2, 3, 5, 7};
int m = arr1.length;
int n = arr2.length;
printIntersection(arr1, arr2, m, n);
}
}
« une boucle » et aucun jeu de hachage est possible que si les tableaux sont classés ou ont une portée limitée des nombres possibles – Slai
Avez-vous essayé cela? http://www.geeksforgeeks.org/union-and-intersection-of-two-sorted-arrays-2/ ** Complexité temporelle: O (m + n) ** –
Salut @Slai, désolé j'ai oublié de le dire , ils sont triés :) – Arturo