find if two arrays contain the same set of integers without extra space and faster than NlogN

前端 未结 14 822
盖世英雄少女心
盖世英雄少女心 2020-12-02 17:27

I came across this post, which reports the following interview question:

Given two arrays of numbers, find if each of the two arrays have the same s

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 18:10

    why not i find the sum , product , xor of all the elements one array and compare them with the corresponding value of the elements of the other array ??

    the xor of elements of both arrays may give zero if the it is like

    2,2,3,3 1,1,2,2

    but what if you compare the xor of the elements of two array to be equal ???

    consider this

    10,3 12,5

    here xor of both arrays will be same !!! (10^3)=(12^5)=9 but their sum and product are different . I think two different set of elements cannot have same sum ,product and xor ! This can be analysed by simple bitvalue examination. Is there anything wrong in this approach ??

提交回复
热议问题