Skip to content

Commit fc63c8b

Browse files
string: Fixed typo & redundent code
1 parent 5e9ea4b commit fc63c8b

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

src/main/java/strings/Bombe.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static int[] solve(int n, int m, char [][] grid) {
6868
baseExponent[i] = safeMod(baseExponent[i - 1] * A);
6969
}
7070

71-
long[] hahes = new long[n];
71+
long[] hashes = new long[n];
7272

7373
Map<Long, Pair<Integer, Integer>> cnt = new HashMap<>();
7474

@@ -79,25 +79,27 @@ public static int[] solve(int n, int m, char [][] grid) {
7979
hash += grid[i][j] * baseExponent[j];
8080
hash = safeMod(hash);
8181
}
82-
hahes[i] = hash;
82+
hashes[i] = hash;
8383
if(cnt.containsKey(hash)) {
8484
cnt.get(hash).first = Math.min(i+1, cnt.get(hash).first);
8585
}else {
86-
cnt.put(hahes[i], new Pair<>(0, i + 1));
86+
cnt.put(hashes[i], new Pair<>(0, i + 1));
8787
}
8888
}
8989

90+
Pair<Integer, Integer> mini = new Pair<>(10_000_000_00, 10_000_000_00);
91+
9092
for (int i = 0; i < n; i++) {
9193
for (int j = 0; j < m; j++) {
92-
hahes[i] -= (grid[i][m - j - 1] * baseExponent[m - 1]) % MOD;
93-
hahes[i] %= MOD;
94-
hahes[i] *= A;
95-
hahes[i] %= MOD;
96-
hahes[i] += grid[i][m - j - 1];
97-
hahes[i] %= MOD;
94+
hashes[i] -= (grid[i][m - j - 1] * baseExponent[m - 1]) % MOD;
95+
hashes[i] %= MOD;
96+
hashes[i] *= A;
97+
hashes[i] %= MOD;
98+
hashes[i] += grid[i][m - j - 1];
99+
hashes[i] %= MOD;
98100

99-
cnt.computeIfAbsent(hahes[i], k -> new Pair<>(0, 0));
100-
Pair<Integer, Integer> pair = cnt.get(hahes[i]);
101+
cnt.computeIfAbsent(hashes[i], k -> new Pair<>(0, 0));
102+
Pair<Integer, Integer> pair = cnt.get(hashes[i]);
101103

102104
if (pair.first == 0 && (i+1) != pair.second) {
103105
pair.first = i + 1;
@@ -112,17 +114,11 @@ public static int[] solve(int n, int m, char [][] grid) {
112114
int temp = pair.first;
113115
pair.first = Math.min(pair.first, pair.second);
114116
pair.second = Math.max(temp, pair.second);
115-
cnt.replace(hahes[i], pair);
116-
}
117-
}
117+
cnt.replace(hashes[i], pair);
118118

119-
Pair<Integer, Integer> mini = new Pair<>(10_000_000_00, 10_000_000_00);
120-
121-
for (Map.Entry<Long, Pair<Integer, Integer>> entry : cnt.entrySet()) {
122-
Pair<Integer, Integer> value = entry.getValue();
123-
124-
if (value.first == 0 || value.second == 0) continue;
125-
if (value.compareTo(mini) < 0) mini = value;
119+
if (pair.first == 0 || pair.second == 0) continue;
120+
if (pair.compareTo(mini) < 0) mini = pair;
121+
}
126122
}
127123

128124
if (mini.first == 10_000_000_00 && mini.second == 10_000_000_00) {

0 commit comments

Comments
 (0)