Skip to content

Commit 2307542

Browse files
committed
Fixed sonar
1 parent b2009a8 commit 2307542

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/java/g3401_3500/s3455_shortest_matching_substring/Solution.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,22 @@ private List<Integer> getMatch(String s, String p) {
1212
int m = p.length();
1313
int[] next = new int[m];
1414
Arrays.fill(next, -1);
15-
for (int i = 1, j = -1; i < m; ++i) {
15+
int i = 1;
16+
int j = -1;
17+
while (i < m) {
1618
while (j != -1 && p.charAt(i) != p.charAt(j + 1)) {
1719
j = next[j];
1820
}
1921
if (p.charAt(i) == p.charAt(j + 1)) {
2022
++j;
2123
}
2224
next[i] = j;
25+
++i;
2326
}
2427
List<Integer> match = new ArrayList<>();
25-
for (int i = 0, j = -1; i < n; ++i) {
28+
i = 0;
29+
j = -1;
30+
while (i < n) {
2631
while (j != -1 && s.charAt(i) != p.charAt(j + 1)) {
2732
j = next[j];
2833
}
@@ -33,6 +38,7 @@ private List<Integer> getMatch(String s, String p) {
3338
match.add(i - m + 1);
3439
j = next[j];
3540
}
41+
++i;
3642
}
3743
return match;
3844
}

src/main/java/g3401_3500/s3456_find_special_substring_of_length_k/Solution.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// #Easy #2025_02_16_Time_0_ms_(100.00%)_Space_42.05_MB_(100.00%)
44

5+
@SuppressWarnings("java:S1871")
56
public class Solution {
67
public boolean hasSpecialSubstring(String s, int k) {
78
if (s.length() == k) {

0 commit comments

Comments
 (0)