-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpatSubstring.java
More file actions
34 lines (32 loc) · 829 Bytes
/
patSubstring.java
File metadata and controls
34 lines (32 loc) · 829 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
33
34
class Question {
public static String charRemove(String str, int p , int q)
{
return str.substring(p + 1, q + 1);
}
public static void main(String[] args) {
String s = "abbabbabbabbababa";
String pattern = "abb";
String temp = "";
int ws = 0 ;
int we = 0;
int count = 0;
int key = pattern.length();
int size = s.length();
while (we < size)
{
temp = temp + s.charAt(we);
if(we - ws + 1 == key)
{
if(pattern.equals(temp))
count++;
temp = charRemove(s , ws , we);
ws++;
}
we++;
}
System.out.println(count);
}
}
//OUTPUT
//java -cp /tmp/uWvNFmaLEV HelloWorld
//4