Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created May 26, 2020 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshallmurphy/15ba87a179c131d28ed7e4a8cdbb5a17 to your computer and use it in GitHub Desktop.
Save marshallmurphy/15ba87a179c131d28ed7e4a8cdbb5a17 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment