Dont understand the inputs


  • 6
    M

    Input:
    2
    [0,2,1,0,2,2,1,2,0,1,1,0,4,1,1,2]

    I assume the first number is the capacity, but what is that array supposed to be?


  • 0

    @Meteo It took me quite a while to figure out how to read this array. Here is how you do it:

    • Read the next number in the array.
    • If it is a zero, call LRUCache.set(). The following 2 integers in the array are the arguments to set().
    • If it is a one, call LRUCache.get(). The following 1 integer in the array is the argument to get().
    • Repeat until the whole array is scanned.

    So in your example:

    [0,2,1,0,2,2,1,2,0,1,1,0,4,1,1,2]

    means

    set(2, 1)
    set(2, 2)
    get(2)
    set(1, 1)
    set(4, 1)
    get(2)

    HTH


Log in to reply
 

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