aboutsummaryrefslogtreecommitdiffstats
path: root/28/main.go
diff options
context:
space:
mode:
Diffstat (limited to '28/main.go')
-rw-r--r--28/main.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/28/main.go b/28/main.go
new file mode 100644
index 0000000..e35583f
--- /dev/null
+++ b/28/main.go
@@ -0,0 +1,40 @@
+package main
+
+import "fmt"
+
+func strStr(haystack string, needle string) int {
+ if len(needle) > len(haystack) {
+ return -1
+ }
+
+ needle_len := len(needle)
+ haystack_len := len(haystack)
+ noMatch := false
+
+ for i, _ := range haystack {
+ if needle_len <= haystack_len-i {
+ for j, _ := range needle {
+ if needle[j] != haystack[i+j] {
+ noMatch = true
+ break
+ }
+ }
+ if noMatch {
+ noMatch = false
+ } else {
+ return i
+ }
+
+ } else {
+ return -1
+ }
+ //fmt.Println(i, h)
+ }
+
+ return -1
+}
+
+func main() {
+ // fmt.Println(strStr("sadbutsad", "sad"))
+ fmt.Println(strStr("mississipi", "a"))
+}