Skip to content

Commit f4f0a39

Browse files
author
Mrinal Chauhan
committed
fix: updated code to fix errors
1 parent 3c54c1d commit f4f0a39

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public static List<Integer> findPatternOccurrences(String text, String pattern)
2222
int[] zArray = calculateZ(combined);
2323
List<Integer> occurrences = new ArrayList<>();
2424
int patternLength = pattern.length();
25-
26-
for (int i = 0; i < zArray.length; i++) {
27-
if (zArray[i] == patternLength) {
25+
//performing z algorithm
26+
for (int i = patternLength + 1; i < zArray.length; i++) {
27+
if (zArray[i] >= patternLength) {
2828
occurrences.add(i - patternLength - 1);
2929
}
3030
}

0 commit comments

Comments
 (0)