Leetcode第28题:找出字符串中第一个匹配项的下标

找出字符串中第一个匹配项的下标

代码实现

class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        str1_length=len(haystack)
        str2_length=len(needle)
        for i in range(str1_length-str2_length+1):
            if haystack[i:i+str2_length]==needle:
                return i
        return -1

解题思路
在这里插入图片描述

最近更新

  1. TCP协议是安全的吗?

    2024-03-26 23:54:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-26 23:54:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-26 23:54:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-26 23:54:04       20 阅读

热门阅读

  1. 使用Spring ORM和MyBatis简化数据库访问

    2024-03-26 23:54:04       15 阅读
  2. 13、Spring CLI中的特殊命令

    2024-03-26 23:54:04       20 阅读
  3. LeetCode1047:删除字符串中的所有相邻重复项

    2024-03-26 23:54:04       23 阅读
  4. Python 命名规则

    2024-03-26 23:54:04       18 阅读
  5. __init__.py 的作用

    2024-03-26 23:54:04       17 阅读
  6. vue3之动态路由

    2024-03-26 23:54:04       18 阅读
  7. Python networkx库中,G.add_edge方法的原理和使用方法

    2024-03-26 23:54:04       17 阅读
  8. 【CSP试题回顾】201912-2-回收站选址(优化)

    2024-03-26 23:54:04       19 阅读
  9. My SQL 子查询

    2024-03-26 23:54:04       20 阅读
  10. MySQL写shell的问题

    2024-03-26 23:54:04       18 阅读
  11. MySQL数据库索引失效的常见情况

    2024-03-26 23:54:04       20 阅读
  12. 构建一个springboot项目

    2024-03-26 23:54:04       19 阅读
  13. macOS Sonoma 14.4.1(23E224)发布(附黑/白苹果镜像)

    2024-03-26 23:54:04       15 阅读
  14. js的变量

    2024-03-26 23:54:04       16 阅读