Dec definition seems incomplete


  • 0
    B

    The sequence of operations Inc(key); Dec(key); is undefined wrt. to problem description. Inc inserts a new element with value 1, then Dec decrements the value, resulting in 0. It is not clear whether the element should disappear (so the description should read "If Key's value is 1 or less") - which would make a sensible data structure, or whether the only way to remove such element is to increment it twice and then decrement?


  • 0

    @bartoszkp

    Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. If the key does not exist, this function does nothing.

    Perhaps reading it like this makes more sense:

    If Key's value is 1, remove it from the data structure. Otherwise decrements an existing key by 1. If the key does not exist, this function does nothing.


  • 1
    B

    @1337c0d3r Yes, that would make sense. For strictness perhaps it should not only be read like this, but also written like this ;)


  • 0

    @bartoszkp Done.


  • 0
    B

    @1337c0d3r Thanks, looks great!


Log in to reply
 

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