mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
16 lines
437 B
C++
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()
|