أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Looping over string characters only once
func firstNotRepeatingCharacter(s: String) -> Character {
var occurrences: [Character:Int] = [:]
s.forEach{ occurrences[$0] = (occurrences[$0] ?? 0) + 1}
return s.first{ occurrences[$0] == 1 } ?? "_"
}