The sequence of operations
Inc(key); Dec(key); is undefined wrt. to problem description.
Inc inserts a new element with value
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?
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.
@1337c0d3r Yes, that would make sense. For strictness perhaps it should not only be read like this, but also written like this ;)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.