require 'set' | |
def palindrome_permutation?(input_string) | |
# create a set to track characters we've seen | |
charSet = Set.new | |
# iterate over each character by spitting into an array | |
input_string.split('').each do |char| | |
# remove from set if previously added | |
if charSet.include? char | |
charSet.delete(char) | |
# add to set if not already present in set | |
else | |
charSet.add(char) | |
end | |
end | |
# set should have 0 or 1 entry if is a palindrome | |
charSet.length <= 1 | |
end |