340. Longest Substring with At Most K Distinct Characters
340. Longest Substring with At Most K Distinct Characters
Description
Given a string s
and an integer k
, return the length of the longest of s
that contains at most k
distinct characters.
Example 1:
1 | Input: s = "eceba", k = 2 |
Example 2:
1 | Input: s = "aa", k = 1 |
Constraints:
1 <= s.length <= 5 * 10^4
0 <= k <= 50
Hints/Notes
- 2025/03/23 Q3
- sliding window
- Leetcode solution
Solution
Language: C++
1 | class Solution { |