File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change 3
3
import java .util .HashMap ;
4
4
import java .util .Map ;
5
5
6
- /**
7
- * 340. Longest Substring with At Most K Distinct Characters
8
- *
9
- * Given a string, find the length of the longest substring T that contains at most k distinct characters.
10
-
11
- For example, Given s = “eceba” and k = 2,
12
-
13
- T is "ece" which its length is 3.
14
-
15
- */
16
6
public class _340 {
17
7
18
8
public static class Solution1 {
@@ -29,7 +19,9 @@ public int lengthOfLongestSubstringKDistinct(String s, int k) {
29
19
num ++;
30
20
}
31
21
if (num > k ) {
32
- while (--count [s .charAt (left ++)] > 0 ) {};
22
+ while (--count [s .charAt (left ++)] > 0 ) {
23
+ }
24
+ ;
33
25
num --;
34
26
}
35
27
result = Math .max (result , right - left + 1 );
@@ -39,7 +31,9 @@ public int lengthOfLongestSubstringKDistinct(String s, int k) {
39
31
}
40
32
41
33
public static class Solution2 {
42
- /**This is a more generic solution for any characters, not limited to ASCII characters.*/
34
+ /**
35
+ * This is a more generic solution for any characters, not limited to ASCII characters.
36
+ */
43
37
public int lengthOfLongestSubstringKDistinct (String s , int k ) {
44
38
Map <Character , Integer > map = new HashMap <>();
45
39
int longest = 0 ;
You can’t perform that action at this time.
0 commit comments