Skip to content

Commit

Permalink
Merge pull request #2128 from AyselHeydarova/Leetcode-0424
Browse files Browse the repository at this point in the history
Create: 0424-longest-repeating-character-replacement.swift
  • Loading branch information
saip7795 authored Jan 23, 2023
2 parents 1391cf6 + 2ea0d43 commit 836d653
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions swift/0424-longest-repeating-character-replacement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
func characterReplacement(_ s: String, _ k: Int) -> Int {
var count: [Character: Int] = [:]
var strArray = Array(s)
var result = 0
var l = 0
var maxF = 0

for r in 0...s.count - 1 {
count[strArray[r]] = count[strArray[r], default: 0] + 1
maxF = max(maxF, count[strArray[r], default: 0])

while (r - l + 1) - maxF > k {
count[strArray[l]] = count[strArray[l], default: 0] - 1
l += 1
}
result = max(result, r - l + 1)
}
return result
}
}

0 comments on commit 836d653

Please sign in to comment.