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
+ ํ์ด :
3
+ ๋ถ๋ถ๋ฌธ์์ด ์ค์ ๊ฐ์ฅ ๋ง์ ๋น๋์ ๋ฌธ์๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ค๋ฅธ ๋ฌธ์๊ฐ k๊ฐ ์ดํ๋ก ์์ผ๋ฉด
4
+ ๊ฐ์ ๋ฐ๋ณต๋ฌธ์์ด๋ก ๋ง๋ค ์ ์๋ค
5
+ sliding window ๊ธฐ๋ฒ์ ํตํด ์ต๋ค๋น๋ ๋ฌธ์์ ๋ค๋ฅธ ๋ฌธ์๊ฐ k๊ฐ ์ด๊ณผ์ด๋ฉด start๋ฅผ ์ด๋์ํจ๋ค
6
+
7
+ SC : O(N)
8
+ start, endํฌ์ธํฐ๋ ๋ฌธ์์ด ๊ธธ์ด์ ๋น๋กํด ๋ฐ๋ณตํด์ ์ด๋ํ๋ฏ๋ก (max ์ฐ์ฐ์ O(26))
9
+
10
+ TC : O(1)
11
+ counter ๋์
๋๋ฆฌ๋ ์ต๋ ์ํ๋ฒณ ๊ฐ์๋งํผ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฐจ์งํ๋ฏ๋ก O(26)์ผ๋ก ์์์ด๋ค๋ค
12
+ """
13
+
14
+ class Solution :
15
+ def characterReplacement (self , s : str , k : int ) -> int :
16
+ start , end = 0 , 0
17
+ counter = {}
18
+ max_len = 0
19
+ while end < len (s ) :
20
+ counter [s [end ]] = counter .get (s [end ], 0 ) + 1
21
+ while end - start + 1 - max (counter .values ()) > k :
22
+ counter [s [start ]] -= 1
23
+ start += 1
24
+ max_len = max (max_len , end - start + 1 )
25
+ end += 1
26
+ return max_len
You canโt perform that action at this time.
0 commit comments