We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fe47f3a commit 43f0c39Copy full SHA for 43f0c39
longest-repeating-character-replacement/kayden.py
@@ -0,0 +1,23 @@
1
+from collections import defaultdict
2
+
3
+class Solution:
4
+ # 시간복잡도: O(N)
5
+ # 공간복잡도: O(N)
6
+ def characterReplacement(self, s: str, k: int) -> int:
7
8
+ n = len(s)
9
+ l, r = 0, 1
10
11
+ d = defaultdict(int)
12
+ d[s[l]] += 1
13
14
+ longest = 1
15
+ while l < r and r < n:
16
+ d[s[r]] += 1
17
+ if r-l+1 - max(d.values()) > k:
18
+ d[s[l]] -= 1
19
+ l += 1
20
+ longest = max(longest, r-l+1)
21
+ r += 1
22
23
+ return longest
0 commit comments