programming-examples/ruby/Algorithms/permutation_palindrome.rb

15 lines
215 B
Ruby
Raw Normal View History

2019-11-15 12:59:38 +01:00
def permutation_palindrome(str)
dict = {}
odds = 0
str.chars.map do |val|
dict[val] = dict[val] ? dict[val] += 1 : 1
end
dict.keys.map do |key|
odds += 1 if dict[key].odd?
end
odds <= 1
end