Why this Expected?


  • 0
    S

    After I submit my code, it said:

    Input: 2,[set(2,1),set(2,2),get(2),set(1,1),set(4,1),get(2)]
    Output: [2,2]
    Expected: [2,-1]

    I thought this test case means, this cache's length is 2. so after [set(2,1),set(2,2),get(2)], cache has contained only one item, that is (2,2),and it has been called one time.

    Then [set(1,1)], the cache is full. So when we [set(4,1)], it will replace the (1,1), and the cache has 2 items in it, that is (2,2) and (4,1). Am I right?


  • 1
    A

    Then [set(1,1)], the cache is full. So when we [set(4,1)], it will replace the (1,1), and the cache has 2 items in it, that is (2,2) and (4,1). Am I right?

    When [set(4,1)], it will replace (2,2), since that is the least recently inserted entry.


  • 0
    X

    Same question. I think the problem says "the least recently used" not "inserted". So that (1,1) should be replaced?


Log in to reply
 

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