NeetCode #227LC-340MediumSliding WindowNC Algo100
← Back to All Problems

#227 · #340 · Longest Substring with At Most K Distinct Characters(至多包含 K 个不同字符的最长子串)

📌 Problem Statement & Constraints

Given a string s and an integer k, return the length of the longest substring that contains at most k distinct characters. Constraints: 1 <= s.length <= 5 * 10^4, 0 <= k <= 50; s consists of ASCII characters.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!