Skip to content

Commit 836d653

Browse files
authored
Merge pull request #2128 from AyselHeydarova/Leetcode-0424
Create: 0424-longest-repeating-character-replacement.swift
2 parents 1391cf6 + 2ea0d43 commit 836d653

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
func characterReplacement(_ s: String, _ k: Int) -> Int {
3+
var count: [Character: Int] = [:]
4+
var strArray = Array(s)
5+
var result = 0
6+
var l = 0
7+
var maxF = 0
8+
9+
for r in 0...s.count - 1 {
10+
count[strArray[r]] = count[strArray[r], default: 0] + 1
11+
maxF = max(maxF, count[strArray[r], default: 0])
12+
13+
while (r - l + 1) - maxF > k {
14+
count[strArray[l]] = count[strArray[l], default: 0] - 1
15+
l += 1
16+
}
17+
result = max(result, r - l + 1)
18+
}
19+
return result
20+
}
21+
}

0 commit comments

Comments
 (0)