-
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
package com.fishercoder.solutions.fourththousand;
public class _3090 {
public static class Solution1 {
public int maximumLengthSubstring(String s) {
int max = 0;
int[] count = new int[26];
for (int left = 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++;
}
}
return max;
}
private boolean qualified(int[] count, char charAt) {
count[charAt - 'a']++;
for (int c : count) {
if (c > 2) {
count[charAt - 'a']--;
return false;
}
}
return true;
}
}
}