Created
June 30, 2025 10:20
-
-
Save enderahmetyurt/2d3c6bae5dd621c839b97bbfa2de73f8 to your computer and use it in GitHub Desktop.
Find the last non-repeating character in a given string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def non_repeat(str) | |
counts = Hash.new(0) | |
str.each_char { |char| counts[char] += 1 } | |
str.reverse.each_char do |char| | |
return char if counts[char] == 1 | |
end | |
"" | |
end | |
puts non_repeat('candy canes do taste yummy') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment