題目:刪除字符串中重復(fù)出現(xiàn)的字符是牢,輸入“FlyElephant”旭等,返回“FlyEephant”.
核心代碼:
<pre><code>`
func deleteDuplicationChar(origin:String) -> String {
var dict:[String:Int] = [:]
var result:String = ""
for i in 0..<origin.characters.count {
let char:String = origin[i]
if dict[char] == nil {
result += char
dict[char] = 1
}
}
return result
}`</code></pre>
測試代碼:
<pre><code>`
var simple:String = hashSearch.deleteDuplicationChar(origin: "FlyElephant")
print("FlyElephant-去除重復(fù)之后的字符串---(simple)")`</code></pre>