Last active
April 8, 2024 18:58
-
-
Save riivanov/e9caafa8afbbfd47e6e8c79fed1b2de2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (i = 0, j = 0; i < n && j < m; i++) { | |
if (txt.charAt(i) == pat.charAt(j)) j++; | |
else { | |
i -= j; | |
j = 0; | |
} | |
} | |
if (j == m) return i - m; // found | |
else return n; // not found | |
// not a match | |
for (int i = 0; i <= n - m; i++) { | |
int j; | |
for (j = 0; j < m; j++) { | |
if (txt.charAt(i+j) != pat.charAt(j)) | |
break; | |
} | |
if (j == m) return i; // found at offset i | |
} | |
return n; // not found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment