Promote the best solution so far

  • 0

    3 reasons for me to consider above solution is the best solution, better than the solution that received the most vostes so far.

    Reason 1: space more efficient and time complexity is as good

    Reason 2: putting fewer elelements in hahset will reduce the chance of collisions happening

    Reason 3: I like one line of codes in the above solution. It further reduces the chance of collisions happening

         if (set.remove(num)) {

    although search time complexity of hashset/hashtable/map is O(1), that is for the average case. In the worst case where collisions happen, the search time complexity could be as bad as O(n). The above codes not only satisfy our search needs but also remove unneeded elements which reduce the chance of collisions happening. I have not seen other solutions take care of collisions better than this solution so far.

    Please vote this solution up and let it receive more deserved votes.

Log in to reply

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