Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Find common elements in two arrays

Go down

Find common elements in two arrays Empty Find common elements in two arrays

Post  yangwenzhou Fri Sep 23, 2011 12:02 pm

If they are sorted:
public static void findCommon(int a[],int b[]){
for(int i=0,j=0;i<a.length&&j<b.length;){
if(a[i]==b[j]){
System.out.print(a[i]+" ");
i++;
j++;
}
else if(a[i]<b[j]){
i++;
}
else
j++;
}
}

if not, hashmap

yangwenzhou

Posts : 5
Join date : 2011-09-23

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum