aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-12-11 19:04:01 +0000
committerterminaldweller <thabogre@gmail.com>2022-12-11 19:04:01 +0000
commit03634721902e6a82160d6e9509274899fa281c4c (patch)
treea797377def22740ac8117cf988d5c1f51cb74c85
parent124 (diff)
downloadleetcode-03634721902e6a82160d6e9509274899fa281c4c.tar.gz
leetcode-03634721902e6a82160d6e9509274899fa281c4c.zip
28
-rw-r--r--28/go.mod3
-rw-r--r--28/main.go40
2 files changed, 43 insertions, 0 deletions
diff --git a/28/go.mod b/28/go.mod
new file mode 100644
index 0000000..6fe8d22
--- /dev/null
+++ b/28/go.mod
@@ -0,0 +1,3 @@
+module 28
+
+go 1.19
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"))
+}