题目:字符串中所有字符是否全不相同.
<pre><code>` func isUniqueChar(str:String)->Bool {
if str.characters.count > 256 {
return false
}
var chars:[Bool] = [Bool].init(repeating: false, count: 256)
for i in 0..<str.characters.count {
let temp:String = str[i] as String
let index:Int = temp.toInt()
if chars[index] {
return false
}
chars[index] = true
}
return true
}`</code></pre>
测试代码:
<pre><code>`var uniqueStr:String = "FlyElephant"
var isUnique:Bool = myString.isUniqueChar(str: uniqueStr)
print("(uniqueStr)---是不是所有字符串唯一:(isUnique)")`</code></pre>