mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
leetcode new problems
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user