Input explanation needed


  • 0
    K

    Can somebody please explain what the inputs mean?

    My code is failing for the following test case:

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

    Output:
    [1,1,2]

    Expected:
    [1,-1,2]

    The following is my code:

    import java.util.*;
    
    public class LRUCache extends LinkedHashMap<Integer, Integer>{
        
        private int cacheSize;
        LinkedHashMap<Integer, Integer> myMap = new LinkedHashMap<Integer, Integer>();
        
        public LRUCache(int capacity) {
            
            super(capacity, 0.75f, true);
            this.cacheSize = capacity;
        }
            
            @Override
            protected boolean removeEldestEntry(Map.Entry<Integer,Integer> eldest)
            {
                return size() > cacheSize;
            }
            
        
        public int get(int key) {
            
            if(myMap.containsKey(key))
            { int val = myMap.get(key);
              return val;
            }
            else
            return -1;
            
        }
        
        public void set(int key, int value) {
            myMap.put(key,value);
        }
    }
    
    

  • 0
    Q
    This post is deleted!

  • 0
    Q

    You can use cout, print to find the format.
    Here is my result, and I don't know what the first 0 is doing.
    Input:
    1
    [0,2,1,1,2,0,3,2,1,2,1,3]
    Output:
    [1,2,2]
    Expected:
    [1,-1,2]
    Stdout:
    capacity = 1
    set(2,1)
    get(2)
    set(3,2)
    erasing key 3
    get(2)
    get(3)


  • 0
    X

    Input:
    1(capacity)
    [0(set),(2,1),1(get),(2),0(set),(3,2),1(get),(2),1(get),(3)]
    So 0 is set and 1 is set;


Log in to reply
 

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