Register now or log in to join your professional community.
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 } ?? "_"
}