Skip to content

Commit e4c9d7a

Browse files
committed
Update naiveStringSearch.go
Properly implemented the algorithm.
1 parent eab0494 commit e4c9d7a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

strings/naiveStringSearch.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import (
1616

1717
func naivePatternSearch(text string, pattern string) []int {
1818
var positions []int
19-
for i := 0; i < len(text); i++ {
19+
for i := 0; i < len(text)-len(pattern); i++ {
2020
var match bool = true
21-
for j := 0; j < len(pattern); j++ {
22-
if text[i+j] != pattern[j] {
21+
j := i +(len(pattern))
22+
if text[i+j] != pattern[j] {
2323
match = false
2424
break
2525
}
26-
}
26+
2727
if match {
2828
positions = append(positions, i)
2929
}

0 commit comments

Comments
 (0)