28-Find-The-Index-Of-The-First-Occurrence-In-A-String
Sat 17 May 2025
https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
m = len(haystack)
n = len(needle)
for i in range(m - n + 1):
if haystack[i:i + n] == needle:
return i
return -1
new Solution().strStr()
Score: 5
Category: leetcode