- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1100.java
26 lines (24 loc) · 780 Bytes
/
_1100.java
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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.HashSet;
importjava.util.Set;
publicclass_1100 {
publicstaticclassSolution1 {
publicintnumKLenSubstrNoRepeats(StringS, intK) {
intcount = 0;
Set<Character> set = newHashSet<>();
for (inti = 0; i <= S.length() - K; i++) {
Stringstring = S.substring(i, i + K);
booleaninvalid = false;
for (charc : string.toCharArray()) {
if (!set.add(c)) {
invalid = true;
break;
}
}
count += invalid ? 0 : 1;
set.clear();
}
returncount;
}
}
}