File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
longest-repeating-character-replacement Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''
2
+ μκ°λ³΅μ‘λ: O(n)
3
+ - λ¬Έμμ΄μ κΈΈμ΄λ§νΌ ν λ²λ§ μνν©λλ€.
4
+ 곡κ°λ³΅μ‘λ: O(n)
5
+ - char_count λμ
λ리λ μ΅λ μνλ²³ 26κ°λ§ μ μ₯ν©λλ€.
6
+ '''
7
+
8
+ class Solution :
9
+ def characterReplacement (self , s : str , k : int ) -> int :
10
+ left = 0
11
+ max_count = 0
12
+ max_length = 0
13
+ char_count = {}
14
+
15
+ for right in range (len (s )):
16
+ char_count [s [right ]] = char_count .get (s [right ], 0 ) + 1
17
+ max_count = max (max_count , char_count [s [right ]])
18
+
19
+ # If the remaining characters exceed the allowed k changes
20
+ while (right - left + 1 ) - max_count > k :
21
+ char_count [s [left ]] -= 1
22
+ left += 1
23
+
24
+ max_length = max (max_length , right - left + 1 )
25
+
26
+ return max_length
You canβt perform that action at this time.
0 commit comments