Find a duplicate in array of integers

后端 未结 4 1471
既然无缘
既然无缘 2021-02-07 18:22

This was an interview question.

I was given an array of n+1 integers from the range [1,n]. The property of the array is that it has k (k&

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-07 19:07

    • It depends what tools are you(your app) can use. Currently a lot of frameworks/libraries exists. For exmaple in case of C++ standart you can use std::map<> ,as maraca mentioned.

    • Or if you have time you can made your own implementation of binary tree, but you need to keep in mind that insert of elements differs in comarison with usual array. In this case you can optimise search of duplicates as it possible in your particular case.

    binary tree expl. ref: https://www.wikiwand.com/en/Binary_tree

提交回复
热议问题