Find common elements in two arrays

View previous topic View next topic Go down

Find common elements in two arrays

Post  yangwenzhou on 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

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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