Created
May 26, 2020 21:41
-
-
Save marshallmurphy/15ba87a179c131d28ed7e4a8cdbb5a17 to your computer and use it in GitHub Desktop.
This file contains 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
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