What is the quickest way to find the first character which only appears once in a string?
In Ruby:
(Original Credit: Andrew A. Smith)
x = "a huge string in which some characters repeat" def first_unique_character(s) s.each_char.detect { |c| s.count(c) == 1 } end first_unique_character(x) => "u"