Replace Characters in a Mutable String
Problem statement
Replace every occurrence of the one-character string from in text with the one-character string to. Return the result.
Function
replaceCharacter(text: String, sourceCharacter: String, targetCharacter: String) → StringExamples
Example 1
text = "banana"sourceCharacter = "a"targetCharacter = "o"return = "bonono"All three a characters become o.
Constraints
0 <= text.length <= 10^6.from.length == to.length == 1.