You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters)
3
+
4
+
<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the length of the longest </em><spandata-keyword="substring-nonempty"><em>substring</em></span><em> of</em> <code>s</code> <em>that contains at most</em> <code>k</code> <em><strong>distinct</strong> characters</em>.</p>
5
+
6
+
<p> </p>
7
+
<p><strongclass="example">Example 1:</strong></p>
8
+
9
+
<pre>
10
+
<strong>Input:</strong> s = "eceba", k = 2
11
+
<strong>Output:</strong> 3
12
+
<strong>Explanation:</strong> The substring is "ece" with length 3.</pre>
13
+
14
+
<p><strongclass="example">Example 2:</strong></p>
15
+
16
+
<pre>
17
+
<strong>Input:</strong> s = "aa", k = 1
18
+
<strong>Output:</strong> 2
19
+
<strong>Explanation:</strong> The substring is "aa" with length 2.
0 commit comments