Skip to content

Commit 99845dd

Browse files
committed
docs: add documentation for KMP algorithm
1 parent f86c802 commit 99845dd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/easy/implement_strstr.rs

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ pub fn str_str(haystack: String, needle: String) -> i32 {
2525
-1
2626
}
2727

28+
/*
29+
Algorithm: KMP (Knuth-Morris-Pratt) Algorithm
30+
31+
1. Build a next array for needle string
32+
2. Compare haystack and needle string
33+
34+
Time: O(m + n)
35+
36+
Space: O(n)
37+
38+
m: haystack length
39+
n: needle length
40+
41+
Reference: https://www.youtube.com/watch?v=GTJr8OvyEVQ
42+
*/
2843

2944
#[test]
3045
fn test_str_str() {

0 commit comments

Comments
 (0)