Untitled
Anonymous
plain_text
08/22/2024 10:42 PM
1.0 KB
17
Indexable
/**
String Compression Algorithm
The task: Input: "aabcccccaaa" Output: "a2b1c5a3"
*/
func stringCompression(input: String) -> String {
var localStr = ""
var count = 1
var tempArray = [String]()
for char in input {
let tempLast = tempArray.last
if tempLast == "\(char)" {
count += 1
if count > 1 {
} else {
}
tempArray.append("\(count)")
continue
}
tempArray.append("\(char)")
}
return ""
}Editor is loading...
Leave a Comment