Skip to content

Commit 34eeeb6

Browse files
author
Mrinal Chauhan
committed
fix: updated code to fix errors
1 parent 198d944 commit 34eeeb6

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/main/java/com/thealgorithms/strings/Zalgorithm.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ public static List<Integer> findPatternOccurrences(String text, String pattern)
2424
int patternLength = pattern.length();
2525

2626
for (int i = patternLength + 1; i < zArray.length; i++) {
27-
if (zArray[i] >= patternLength) {
27+
if (zArray[i] == patternLength) {
2828
occurrences.add(i - patternLength - 1);
29-
30-
// Modification to handle single and multi-character patterns differently:
31-
// Skip to next position for non-overlapping matches only if pattern length > 1
32-
if (patternLength > 1) {
33-
i += patternLength - 1;
34-
}
35-
// For single-character patterns, continue without skipping to capture overlaps
3629
}
3730
}
3831
return occurrences;

0 commit comments

Comments
 (0)