class Solution {
public:
int strStr(string haystack, string needle) {
int m = haystack.size(), n = needle.size();
int idx = 0;
while (idx < m) {
int start = idx;
int cur = 0;
while (idx < m && cur < n && haystack[idx] == needle[cur]) {
cur += 1;
idx += 1;
}
if (cur == n) return start;
idx = start + 1;
}
return -1;
}
};
Time Complexity: O(m * n)
Space: O(1)