Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaeebda0

Browse files
edit 146
1 parenta369814 commitaeebda0

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
returnnode.value;
109117
}
110118
}
@@ -133,14 +141,6 @@ public void set(int key, int value) {
133141
}
134142
}
135143

136-
privatevoidupdate(DoublyLinkedListPlusHashMapSolution.Nodenode) {
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
privatevoidremove(DoublyLinkedListPlusHashMapSolution.Nodenode) {
145145
DoublyLinkedListPlusHashMapSolution.Nodenext =node.next,prev =node.prev;
146146
prev.next =next;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp