Why can not there be duplicated numbers in the array.


  • 2
    M

    The problem does not indicate if there could be duplicated number in the list or not? if there are, most of the solutions to use dict should not work since they use the list value as the dict key.


  • 0
    E

    Actually you're right. Most of solutions does not handle case when input array contains duplicates, but to handle such situation you need just to use std:multimap + std::multimap::equal_range. And it will not decrease performance cause you should return first pair of not equal indices.


Log in to reply
 

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