-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode_Implement_strSTR.cpp
More file actions
43 lines (43 loc) · 1.04 KB
/
Leetcode_Implement_strSTR.cpp
File metadata and controls
43 lines (43 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public:
int strStr(string haystack, string needle) {
if(needle.length()==0)
{
return 0;
}
int Flag=2;
int i,j,k;
for(i=0;i<haystack.length();i++)
{
if(haystack[i]==needle[0])
{
if(i+needle.length()>haystack.length())
{
Flag=0;
break;
}
else
{
for(j=0;j<needle.length();j++)
{
if(haystack[i+j]!=needle[j])
{
Flag=0;
break;
}
else
{
Flag=1;
}
cout<<"Flag is "<<Flag;
}
}
}
if(Flag==1)
{
return i;
}
}
return -1;
}
};