All elements distinct?


  • 0
    Z

    Should all elements in the array be distinct?


  • 1
    M

    No, each element does not need to be distinct. Since you are returning indices, which do need to be distinct (in1 < in2), the two could have the same content and have different indices to be a valid sum.

    {2,2,3,5} sum = 4 would return 0,1, since the same index cannot be chosen twice, and must maintain an internal order, leaving only one solution.


  • 0
    Z

    Thanks! I just saw some other guy posed "2,2,3,5" is a wrong case


  • 0
    M

    And sorry, it would return 1,2, as the indices are 1-based, not 0-based.


Log in to reply
 

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