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

Commit8ba7179

Browse files
refactor 532
1 parentc654d01 commit8ba7179

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,31 @@ The pairs (i, j) and (j, i) count as the same pair.
3232
*/
3333
publicclass_532 {
3434

35-
publicintfindPairs(int[]nums,intk) {
36-
if (nums ==null ||nums.length ==0 ||k <0) {
37-
return0;
38-
}
35+
publicstaticclassSolution1 {
36+
publicintfindPairs(int[]nums,intk) {
37+
if (nums ==null ||nums.length ==0 ||k <0) {
38+
return0;
39+
}
3940

40-
Map<Integer,Integer>map =newHashMap();
41-
for (intnum :nums) {
42-
map.put(num,map.getOrDefault(num,0) +1);
43-
}
41+
Map<Integer,Integer>map =newHashMap();
42+
for (intnum :nums) {
43+
map.put(num,map.getOrDefault(num,0) +1);
44+
}
4445

45-
intanswer =0;
46-
for (intkey :map.keySet()) {
47-
if (k ==0) {
48-
if (map.get(key) >=2) {
49-
answer++;
50-
}
51-
}else {
52-
if (map.containsKey(key +k)) {
53-
answer++;
46+
intanswer =0;
47+
for (intkey :map.keySet()) {
48+
if (k ==0) {
49+
if (map.get(key) >=2) {
50+
answer++;
51+
}
52+
}else {
53+
if (map.containsKey(key +k)) {
54+
answer++;
55+
}
5456
}
5557
}
58+
returnanswer;
5659
}
57-
returnanswer;
5860
}
5961

6062
}

‎src/test/java/com/fishercoder/_532Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
importstaticjunit.framework.Assert.assertEquals;
1313

1414
publicclass_532Test {
15-
privatestatic_532test;
15+
privatestatic_532.Solution1test;
1616
privatestaticintexpected;
1717
privatestaticintactual;
1818
privatestaticintk;
1919
privatestaticint[]nums;
2020

2121
@BeforeClass
2222
publicstaticvoidsetup()throwsIOException {
23-
test =new_532();
23+
test =new_532.Solution1();
2424
Propertiesproperties =newProperties();
2525
InputStreaminputStream =_532.class.getClassLoader().getResourceAsStream("fishercoder.properties");
2626
properties.load(inputStream);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp