Skip to content

Commit f2d88f1

Browse files
refactor 340
1 parent 9975940 commit f2d88f1

File tree

1 file changed

+6
-12
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-12
lines changed

src/main/java/com/fishercoder/solutions/_340.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

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-
*/
166
public class _340 {
177

188
public static class Solution1 {
@@ -29,7 +19,9 @@ public int lengthOfLongestSubstringKDistinct(String s, int k) {
2919
num++;
3020
}
3121
if (num > k) {
32-
while (--count[s.charAt(left++)] > 0) {};
22+
while (--count[s.charAt(left++)] > 0) {
23+
}
24+
;
3325
num--;
3426
}
3527
result = Math.max(result, right - left + 1);
@@ -39,7 +31,9 @@ public int lengthOfLongestSubstringKDistinct(String s, int k) {
3931
}
4032

4133
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+
*/
4337
public int lengthOfLongestSubstringKDistinct(String s, int k) {
4438
Map<Character, Integer> map = new HashMap<>();
4539
int longest = 0;

0 commit comments

Comments
 (0)