- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3090.java
31 lines (29 loc) · 941 Bytes
/
_3090.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
27
28
29
30
31
packagecom.fishercoder.solutions.fourththousand;
publicclass_3090 {
publicstaticclassSolution1 {
publicintmaximumLengthSubstring(Strings) {
intmax = 0;
int[] count = newint[26];
for (intleft = 0, right = 0; right < s.length() && left < s.length(); ) {
if (qualified(count, s.charAt(right))) {
max = Math.max(max, right - left + 1);
right++;
} else {
count[s.charAt(left) - 'a']--;
left++;
}
}
returnmax;
}
privatebooleanqualified(int[] count, charcharAt) {
count[charAt - 'a']++;
for (intc : count) {
if (c > 2) {
count[charAt - 'a']--;
returnfalse;
}
}
returntrue;
}
}
}