MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / put

Method put

Java/LRU-Cache.java:35–56  ·  view source on GitHub ↗
(int key, int value)

Source from the content-addressed store, hash-verified

33 }
34
35 public void put(int key, int value) {
36 Node node = map.get(key);
37 if(node!=null)
38 {
39 remove(node);
40 node.val = value;
41 add(node);
42 }
43 else{
44 if(map.size() == capacity)
45 {
46 map.remove(tail.prev.key);
47 remove(tail.prev);
48 }
49 Node new_node = new Node();
50
51 new_node.key = key;
52 new_node.val = value;
53 map.put(key, new_node);
54 add(new_node);
55 }
56 }
57
58 public void add(Node node)
59 {

Callers 3

twoSumMethod · 0.45
findShortestSubArrayMethod · 0.45
firstUniqCharMethod · 0.45

Calls 3

removeMethod · 0.95
addMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected