类 RabinKarp
- java.lang.Object
-
- edu.princeton.cs.algs4.RabinKarp
-
public class RabinKarp extends java.lang.Object
TheRabinKarp
class finds the first occurrence of a pattern string in a text string.This implementation uses the Rabin-Karp algorithm.
For additional documentation, see Section 5.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
方法概要
修饰符和类型 方法 说明 static void
main(java.lang.String[] args)
Takes a pattern string and an input string as command-line arguments; searches for the pattern string in the text string; and prints the first occurrence of the pattern string in the text string.int
search(java.lang.String txt)
Returns the index of the first occurrrence of the pattern string in the text string.
-
-
-
方法详细资料
-
search
public int search(java.lang.String txt)
Returns the index of the first occurrrence of the pattern string in the text string.- 参数:
txt
- the text string- 返回:
- the index of the first occurrence of the pattern string in the text string; n if no such match
-
main
public static void main(java.lang.String[] args)
Takes a pattern string and an input string as command-line arguments; searches for the pattern string in the text string; and prints the first occurrence of the pattern string in the text string.- 参数:
args
- the command-line arguments
-
-