Skip to content

Commit 6f078b2

Browse files
committed
add: initial implementation of Rabin-Karp algorithm for string matching
1 parent 7c622d9 commit 6f078b2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public static List<String> search(String text, String pattern) {
5959

6060
// Calculating hash value for next window of text: Remove leading digit, add trailing digit
6161
if (i < n - m) {
62-
textHash = (256 * (textHash - text.charAt(i) * h) + text.charAt(i + m)) % prime;
62+
textHash = (256 * textHash - text.charAt(i) * h + text.charAt(i + m)) % prime;
6363

64-
// We might get negative value of textHash,so converting it to positive
64+
// We might get negative value of textHash, so converting it to positive
6565
if (textHash < 0) {
6666
textHash = (textHash + prime);
6767
}

0 commit comments

Comments
 (0)