File tree 1 file changed +9
-9
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,15 @@ public int get(int key) {
104
104
if (node == null ) {
105
105
return -1 ;
106
106
} 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
+
108
116
return node .value ;
109
117
}
110
118
}
@@ -133,14 +141,6 @@ public void set(int key, int value) {
133
141
}
134
142
}
135
143
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
-
144
144
private void remove (DoublyLinkedListPlusHashMapSolution .Node node ) {
145
145
DoublyLinkedListPlusHashMapSolution .Node next = node .next , prev = node .prev ;
146
146
prev .next = next ;
You can’t perform that action at this time.
0 commit comments