- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutationInString.java
More file actions
Latest commit
29 lines (29 loc) · 774 Bytes
/
Copy pathPermutationInString.java
File metadata and controls
29 lines (29 loc) · 774 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
classSolution {
publicbooleancheckInclusion(Strings1, Strings2) {
if(s1.length() > s2.length()){
returnfalse;
}
int[] freq = newint[26];
for(inti = 0; i < s1.length(); i++){
freq[s1.charAt(i) - 'a']++;
}
for(inti = 0; i < s2.length(); i++){
freq[s2.charAt(i) - 'a']--;
if(i - s1.length() >= 0){
freq[s2.charAt(i - s1.length()) - 'a']++;
}
if(allZeros(freq)){
returntrue;
}
}
returnfalse;
}
privatebooleanallZeros(int[] f){
for(inti = 0; i < 26; i++){
if(f[i] != 0){
returnfalse;
}
}
returntrue;
}
}