MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / put

Method put

java/0146-lru-cache.java:30–43  ·  view source on GitHub ↗
(int key, int value)

Source from the content-addressed store, hash-verified

28 }
29
30 public void put(int key, int value) {
31 if (cache.containsKey(key)) {
32 remove(cache.get(key));
33 }
34 cache.put(key, new Node(key, value));
35 insert(cache.get(key));
36
37 if (cache.size() > capacity) {
38 // remove from the list and delte the LRU from the hashmap
39 Node lru = this.left.next;
40 remove(lru);
41 cache.remove(lru.key);
42 }
43 }
44
45 // remove node from list
46 public void remove(Node node) {

Callers

nothing calls this directly

Calls 4

removeMethod · 0.95
insertMethod · 0.95
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected