Given a string S, find the length of the longest substring T that contains at most k distinct characters.
Example
No.1
Input: S = “eceba” and k = 3
Output: 4
Explanation: T = “eceb”
No.2
Input: S = “WORLD” and k = 4
Output: 4
Explanation: T = “WORL” or “ORLD”
Challenge
O(n) time
Code
1 | public int lengthOfLongestSubstringKDistinct(String s, int k) { |