How to efficiently remove duplicates from an array without using Set

后端 未结 30 2790
情深已故
情深已故 2020-11-22 07:29

I was asked to write my own implementation to remove duplicated values in an array. Here is what I have created. But after tests with 1,000,000 elements it took very long ti

30条回答
  •  春和景丽
    2020-11-22 07:35

    What if you create two boolean arrays: 1 for negative values and 1 for positive values and init it all on false.

    Then you cycle thorugh the input array and lookup in the arrays if you've encoutered the value already. If not, you add it to the output array and mark it as already used.

提交回复
热议问题