Files
2026-02-11 14:56:22 +05:30

16 lines
437 B
C++

class Solution{
public:
int strStr(string haystack, string needle){
if(needle.length() > haystack.length()) return -1;
for(int i =0;i <= haystack.length() - needle.length();i++){
if(haystack.substr(i, needle.length()) == needle)
return i;
}
return -1;
}
};
// TC : O(n*m)
// SC : O(m)
// m-> needle.length(), n-> haystack.length()