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

前端 未结 14 805
盖世英雄少女心
盖世英雄少女心 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条回答
  •  隐瞒了意图╮
    2020-12-02 17:47

    For each integer i check that the number of occurrences of i in the two arrays are either both zero or both nonzero, by iterating over the arrays.

    Since the number of integers is constant the total runtime is O(n).

    No, I wouldn't do this in practice.

提交回复
热议问题