Can anyone tell me the difference between these two snippet of code.
A and B are ArrayList< Integer>
This one gets accepted.
for(int i=0;i<A.size();i++){
for(int j=0;j<B.size();j++){
int X = A.get(i);
int Y = B.get(j);
if(X == Y)
ans = X;
}
}
This one is giving WA
for(int i=0;i<A.size();i++){
for(int j=0;j<B.size();j++){
if(A.get(i) == B.get(j))
ans = A.get(i);
}
}