forked from pxu/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindSubstrs.java
More file actions
43 lines (34 loc) · 1.16 KB
/
FindSubstrs.java
File metadata and controls
43 lines (34 loc) · 1.16 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
public class FindSubstrs {
static void findSubstrs(char[] s, char[] pat) {
int[] need = new int[26];
int[] found = new int[26];
char[] pat = pattern.toCharArray();
for(char c: pat) need[c - 'a'] += 1;
int n = s.length();
List<Integer> re = new ArrayList<> ();
int len = 0;
int sum = 0;
int l = 0, r = 0;
for(; r<n; ++r) {
char c = s[r];
int v = c - 'a';
sum = (sum + v) % pat.length;
mod[sum] += 1;
found[s[r] - 'a'] += 1;
if(found[s[r] - 'a'] <= need[s[r] - 'a']) len += 1;
if(len == pat.length) {
while(l <= r && (need[s[l] - 'a'] == 0 || found[s[l] - 'a'] > need[s[l] - 'a'])) {
if(found[s[l] - 'a'] > need[s[l] - 'a']) found[s[l] - 'a'] -= 1;
l += 1;
}
if(r-l+1 == pat.length) {
re.add(l);
}
}
} // end for loop
int module = 0;
for(char c: pat) module = (module + (c - 'a')) % (pat.length);
for(int i=0; i<n; ++i) {
}
}
}