Skip to content

Commit 86f42c3

Browse files
authored
Fixed sonar warnings.
1 parent 87b87ac commit 86f42c3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/main/java/g1701_1800/s1726_tuple_with_same_product/Solution.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@
33
// #Medium #Array #Hash_Table #2022_04_28_Time_235_ms_(90.73%)_Space_63.4_MB_(87.42%)
44

55
import java.util.HashMap;
6+
import java.util.Map;
67

78
public class Solution {
89
public int tupleSameProduct(int[] nums) {
910
HashMap<Integer, Integer> ab = new HashMap<>();
10-
1111
for (int i = 0; i < nums.length; i++) {
1212
for (int j = i + 1; j < nums.length; j++) {
1313
ab.put(nums[i] * nums[j], ab.getOrDefault(nums[i] * nums[j], 0) + 1);
1414
}
1515
}
16-
1716
int count = 0;
18-
for (Integer key : ab.keySet()) {
19-
int val = ab.get(key);
17+
for (Map.Entry<Integer, Integer> entry : ab.entrySet()) {
18+
int val = entry.getValue();
2019
count = count + (val * (val - 1)) / 2;
2120
}
22-
2321
return count * 8;
2422
}
2523
}

src/main/java/g1701_1800/s1728_cat_and_mouse_ii/Solution.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import java.util.ArrayList;
77
import java.util.List;
88

9+
@SuppressWarnings("unchecked")
910
public class Solution {
10-
private final int mouseTurn = 0;
11+
private static final int MOUSE_TURN = 0;
1112
private final List<Integer>[][] graphs = new List[2][];
1213
private int foodPos;
1314
private int[][][] memo;
@@ -42,7 +43,7 @@ public boolean canMouseWin(String[] grid, int catJump, int mouseJump) {
4243
dfs(i * n + j, foodPos, catTurn);
4344
}
4445
}
45-
return memo[mousePos][catPos][mouseTurn] < 0;
46+
return memo[mousePos][catPos][MOUSE_TURN] < 0;
4647
}
4748

4849
private List<Integer>[] buildGraph(int jump, String[] grid) {
@@ -86,9 +87,7 @@ private void dfs(int p1, int p2, int turn) {
8687
memo[p1][p2][turn] = -1;
8788
turn ^= 1;
8889
for (int w : graphs[turn][p2]) {
89-
if (turn == mouseTurn) {
90-
dfs(w, p1, turn);
91-
} else if (++memo[w][p1][turn] == graphs[turn][w].size()) {
90+
if (turn == MOUSE_TURN || ++memo[w][p1][turn] == graphs[turn][w].size()) {
9291
dfs(w, p1, turn);
9392
}
9493
}

0 commit comments

Comments
 (0)