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

Commit081c371

Browse files
author
jsquared21
committed
Edit method MyHashMap.get(key) for efficiency
1 parent5c40747 commit081c371

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed
-15 Bytes
Binary file not shown.

‎Exercise_27/Exercise_27_04/MyHashMap.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,16 @@ public java.util.Set<Entry<K, V>> entrySet() {
8888
@Override/** Return the value that matched the specified key */
8989
publicVget(Kkey) {
9090
intindex =hash(key.hashCode());
91-
inti =index -1;
9291

93-
while (i !=index && (table.get(index) ==null ||
94-
table.get(index).getKey() !=key)) {
92+
while (table.get(index) !=null) {
93+
if (table.get(index).getKey().equals(key)) {
94+
returntable.get(index).getValue();
95+
}
96+
9597
index++;
9698
index %=capacity;
9799
}
98100

99-
if (table.get(index).getKey() ==key) {
100-
returntable.get(index).getValue();
101-
}
102-
103101
returnnull;
104102
}
105103

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp