
class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        # 特殊情况处理
        if not needle:
            return 0
        
        # 获取 haystack 和 needle 的长度
        a = len(needle)
        b = len(haystack)
        
        # 遍历 haystack,检查每个子字符串是否与 needle 匹配
        for i in range(b - a + 1):
            if haystack[i:i + a] == needle:
                return i
        
        # 如果没有找到匹配项,返回 -1
        return -1


















![[网络安全]数据安全领域关键技术总结](https://img-blog.csdnimg.cn/8c06569f5daf4f8cb2519086ffd4da9e.png#pic_center)
