May be a wrong test case, when set with existing key.

  • 0

    Maybe a problem of understanding:

    In the Question:
    "set(key, value) - Set or insert the value if the key is not already present."

    => so I think that means when set with an existing key just ignore it;

    The test case:


    So step is

    3,1 keep
    2,1 keep
    2, 2 ignore
    4, 4 keep, and drop 3,1
    get 2, returns 1;

  • 0

    I think the way to read that is set or (insert the value if the key is not present). If you read it like that, then it means that the new value should override the existing one. If you do this, you will pass the tests.

  • 1

    @cosminBoaca Hi, I have a question. If the new value overrides the value of key "2" in the fourth step, should I increase the frequency of key "2" by 1? or just reset its frequency to 1? Thanks.

  • 1

    @zhangchunli you need to increase the frequency to pass the tests

  • 0
    L thanks, just accepted when increase the frequency

Log in to reply

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