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

Commitc6544b2

Browse files
refactor 706
1 parent570a498 commitc6544b2

File tree

1 file changed

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

1 file changed

+29
-0
lines changed

‎src/main/java/com/fishercoder/solutions/_706.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
packagecom.fishercoder.solutions;
22

3+
importjava.util.Arrays;
4+
35
publicclass_706 {
46
publicstaticclassSolution1 {
57
/**
@@ -163,4 +165,31 @@ public void remove(int key) {
163165
}
164166
}
165167
}
168+
169+
publicstaticclassSolution3 {
170+
/**
171+
* My completely original, but hacky and cheaty solution to take full advantage of the problem constraints.
172+
*/
173+
publicstaticclassMyHashMap {
174+
175+
int[]map;
176+
177+
publicMyHashMap() {
178+
map =newint[1000001];
179+
Arrays.fill(map, -1);
180+
}
181+
182+
publicvoidput(intkey,intvalue) {
183+
map[key] =value;
184+
}
185+
186+
publicintget(intkey) {
187+
returnmap[key];
188+
}
189+
190+
publicvoidremove(intkey) {
191+
map[key] = -1;
192+
}
193+
}
194+
}
166195
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp