Skip to content

Commit ac674d5

Browse files
committed
Time: 136 ms (17.29%) | Memory: 16.6 MB (80.27%) - LeetSync
1 parent 0641f9c commit ac674d5

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
class Solution:
22
def characterReplacement(self, s: str, k: int) -> int:
3-
map = {}
4-
l = 0
5-
res = 0
63

7-
for i in range(len(s)):
8-
map[s[i]] = map.get(s[i], 0) + 1
4+
left = 0
5+
map = defaultdict(int)
6+
ans = 0
97

10-
if (i - l +1) - max(map.values()) > k:
11-
map[s[l]] = map[s[l]] -1
12-
l +=1
8+
for right in range(len(s)):
9+
map[s[right]] = map.get(s[right], 0) +1
10+
while (right -left +1) - max(map.values()) > k:
11+
map[s[left]] -=1
12+
if map[left] == 0:
13+
del map[left]
14+
left +=1
1315

14-
res = max(res, i-l +1)
15-
return res
16-
16+
17+
ans = max(ans, right -left +1)
18+
return ans
19+
20+
21+

0 commit comments

Comments
 (0)