Check if 2 arrays are similar without hashing or sorting

后端 未结 4 1090
南旧
南旧 2021-01-13 10:20

We need to check if 2 arrays are similar or not. The elements can be duplicate as well. For example A = {2,3,4,5,6,6} and B = {3,6,2,4,6,5} are similar.

I have a nai

4条回答
  •  庸人自扰
    2021-01-13 10:55

    i just want to mention that u don't have to run your algorithm(whether it has a complexity of o(n*m) or max(n,m)) for all input combinations.Run your algorithm only if xor of all the elements of both arrays is equal to zero. i.e a[0] xor a[1] xor...b[0] xor...b[n]=0. otherwise u can surely say that array A and B is not equal.

提交回复
热议问题