@@ -0,0 +1,658 @@
+package advanced.scan.window.lc340_longestsubstringwithatmostkdistinctcharacters;%0A%0A/**%0A */%0Apublic class Solution %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        Solution sol = new Solution();%0A        System.out.println(sol.longestSubstr(%22eceba%22, 3));%0A    %7D%0A%0A    public int longestSubstr(String s, int k) %7B%0A        int%5B%5D cnt = new int%5B255%5D;%0A        int max = 0, from = 0, size = 0;%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            if (cnt%5Bs.charAt(i)%5D++ == 0) size++;%0A            while (size %3E k)%0A                if (--cnt%5Bs.charAt(from++)%5D == 0) size--;%0A            max = Math.max(max, i - from + 1);%0A        %7D%0A        return max;%0A    %7D%0A%0A%7D%0A

longest substring with at most distinct characters