Is the expected answer right ?


  • 0
    L

    Submission Result: Wrong Answer

    Input: 2,[get(2),set(2,6),get(1),set(1,5),set(1,2),get(1),get(2)]

    Output: [-1,-1,2,-1]

    Expected: [-1,-1,2,6]

    In this situation, when we set (1,2), the cache will reach the capacity so that we should invalidate (2,6) before insert (1,2). The question is, why the expected answer is 6 when we execute get(2) ? Actually, (2,6) is no longer in the queue.


  • 0
    S

    set(2, 6) means set value 6 for key 2, in your test case, there are only 2 keys 1 and 2, so the capacity is always enough.


  • 0
    L

    got it! thanks :)


Log in to reply
 

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