find-the-index-of-the-first-occurrence-in-a-string Jan 21, 2024 class Solution { fun strStr(haystack: String, needle: String): Int { if (haystack == needle) return 0 for (i in 0..haystack.length - needle.length) { if (haystack.substring(i, i + needle.length) == needle) return i } return -1 } }