LeetCode算法入门- Implement strStr() -day22
LeetCode算法入門- Implement strStr() -day22
Implement strStr().
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Example 1:
Input: haystack = “hello”, needle = “ll”
Output: 2
Example 2:
Input: haystack = “aaaaa”, needle = “bba”
Output: -1
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().
題目分析:
通過兩個for循環來實現
Java實現:
總結
以上是生活随笔為你收集整理的LeetCode算法入门- Implement strStr() -day22的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式---观察者模式介绍与理解
- 下一篇: 一篇博客读懂设计模式之-----策略模式