forked from Itachi-Ucchiha/BasicDSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22ndJune(I).java
More file actions
32 lines (26 loc) · 730 Bytes
/
Copy path22ndJune(I).java
File metadata and controls
32 lines (26 loc) · 730 Bytes
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
public class rough {
static int strStr2(String haystack, String needle){
for(int i =0; i<haystack.length();i++){
int count =0;
for(int j = 0;j<needle.length() && i+j<haystack.length();j++){
if(haystack.charAt(i+j)==needle.charAt(j)){
count++;
}
else{
break;
}
}
if(count==needle.length()){
return i;
}
count = 0;
}
return -1;
}
public static void main(String[] args) {
String haystack = "mississippi";
String needle = "issip";
System.out.println(strStr1(haystack,needle));
System.out.println(strStr2(haystack,needle));
}
}