forked from ghostmkg/programming-language
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode_567.java
More file actions
Latest commit
35 lines (33 loc) · 1 KB
/
Copy pathLeetcode_567.java
File metadata and controls
35 lines (33 loc) · 1 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
publicclassLeetcode_567 {
publicbooleancheckInclusion(Strings1, Strings2) {
int[] freq1 = newint[26];
int[] freq2 = newint[26];
intn1 = s1.length();
intn2 = s2.length();
intl = 0, r = n1;
if (n2 < n1) returnfalse;
for (inti = 0; i < n1; i++) {
freq1[s1.charAt(i) - 'a']++;
freq2[s2.charAt(i) - 'a']++;
}
while (r <= n2) {
if (isMatching(freq1, freq2)) returntrue;
freq2[s2.charAt(l) - 'a']--;
if (r < n2)
freq2[s2.charAt(r) - 'a']++;
l++;
r++;
}
returnfalse;
}
privatebooleanisMatching(int[] freq1, int[] freq2) {
for (inti = 0; i < 26; i++) {
if (freq1[i] != freq2[i]) returnfalse;
}
returntrue;
}
publicstaticvoidmain(String[] args) {
Leetcode_567obj = newLeetcode_567();
System.out.println(obj.checkInclusion("ab", "eidbaooo"));
}
}