I have slow and fast solution, but both perform equally slow in LeetCode submission

  • 0

    I implemented two C++ solutions of the problem and tested CPU time of both on my laptop. My "slow" solution is based on calling erase method on each duplicate element (clearly inefficient solution). My "fast" solution also uses erase method, but erase is called only for a range of duplicate elements to minimize reallocation of elements. In my tests at my laptop, my "fast" solution almost always factor of two faster than the "slow" one. However, when I submitted both of these solutions they got almost the same time. This is weird... of course it may depend on a test sample... The only case when my two solutions have similar time is when the last two elements are duplicates. In all other cases I had substantial improvement in CPU. Does anyone have any insights why this happens?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.