题目描述
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
我的解法
解题思路
实现代码
1 | class Solution { |
Runtime: 8 ms, faster than 80.56% of C++ online submissions for Implement strStr().
Memory Usage: 9.3 MB, less than 53.68% of C++ online submissions for Implement strStr().