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

前端 未结 14 800
盖世英雄少女心
盖世英雄少女心 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
    2020-12-02 18:07

    If the arrays have the same size, and there are guaranteed to be no duplicates, sum each of the arrays. If the sum of the values is different, then they contain different integers.

    Edit: You can then sum the log of the entries in the arrays. If that is also the same, then you have the same entries in the array.

提交回复
热议问题