Finding common elements in two arrays of different size

后端 未结 10 844
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 18:08

I have a problem to find common elements in two arrays and that\'s of different size.

Take , Array A1 of size n and Array A2 o

10条回答
  •  -上瘾入骨i
    2020-12-14 18:53

    In Python, you would write set(A1).intersection(A2). This is the optimal O(n + m).

    There's ambiguity in your question though. What's the result of A1=[0, 0], A2=[0, 0, 0]? There's reasonable interpretations of your question that give 1, 2, 3, or 6 results in the final array - which does your situation require?

提交回复
热议问题