Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aeebda0

Browse files
edit 146
1 parent a369814 commit aeebda0

File tree

1 file changed

+9
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+9
-9
lines changed

src/main/java/com/fishercoder/solutions/_146.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ public int get(int key) {
104104
if (node == null) {
105105
return -1;
106106
} else {
107-
update(node);
107+
108+
/**Do two operations: this makes the process more clear:
109+
* remove the old node first, and then
110+
* just add the node again.
111+
* This will guarantee that this node will be at the latest position:
112+
* the most recently used position.*/
113+
remove(node);
114+
add(node);
115+
108116
return node.value;
109117
}
110118
}
@@ -133,14 +141,6 @@ public void set(int key, int value) {
133141
}
134142
}
135143

136-
private void update(DoublyLinkedListPlusHashMapSolution.Node node) {
137-
/** this simplifies the process, just do two operations, remove the old node first, and then
138-
just add the node again this will guarantee that this node will be at the latest position:
139-
the most recently used position.*/
140-
remove(node);
141-
add(node);
142-
}
143-
144144
private void remove(DoublyLinkedListPlusHashMapSolution.Node node) {
145145
DoublyLinkedListPlusHashMapSolution.Node next = node.next, prev = node.prev;
146146
prev.next = next;

0 commit comments

Comments
 (0)