[leetcode] 28. Implement strStr()

Description

Implement strStr().

Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Example 1:

Example 2:

Clarification:

What should we return when needle is an empty string? This is a great question to ask during an interview.

For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C’s strstr() and Java’s indexOf().

题目的意思是:实现一个strStr()函数,返回在haystack中首先出现needle字符串的索引。

  • 这个问题是一个字符串匹配问题,我在这里很激烈地解决了。
    [En]

    this problem is a string matching problem, which I solved violently here.*

  • 当然这道题还有优化的KMP算法,我调了几遍没有ac,以后有机会补上KMP版本。

参考文献

Original: https://blog.51cto.com/u_9453611/5569062
Author: 是念
Title: [leetcode] 28. Implement strStr()

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/508233/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球