ask. help me to compare two array of integers and the order does not matter.
Posted
by stdnoit
on Stack Overflow
See other posts from Stack Overflow
or by stdnoit
Published on 2010-04-19T06:41:31Z
Indexed on
2010/04/19
6:53 UTC
Read the original article
Hit count: 192
[Example]
<1 2 3 4> = <3 1 2 4>
<1 2 3 4> != <3 4 1 1>
and ummm it is in java. cant use hashmap table or anything just pure without library.
I know there are two ways.
1. sort them and compare the array index by index
2. use two for loops and compare the outer index with the inner index. ( i have been trying with this but still not working)
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(a[i] != a[j] && j == n)
return false;
}
}
return true;
anything wrong with the code ? thanks
© Stack Overflow or respective owner