lib/palindrome_permutation.rb
# O(n) time complexity, where n is the chars in the string
# O(n) space complexity
O(n) time complexity, where n is the chars in the string
O(n) space complexity
O ( n ) time complexity where n is the chars in the string O ( n ) space complexity
def palindrome_permutation?(string)
  return true if string == ""
  array = string.split("")
  hash = {}
  array.each do |letter|
    if hash[letter].nil?
      hash[letter] = 1
    else
      hash[letter] += 1
    end
  end
  return hash.count {|k,v| v.odd?} == 1
end
def palindrome_permutation? ( string ) return true if string == "" array = string . split ( "" ) hash = { } array . each do | letter | if hash [ letter ] . nil? hash [ letter ] = 1 else hash [ letter ] += 1 end end return hash . count { | k , v | v . odd? } == 1 end
O(n) time complexity, where n is the chars in the string
O(n) space complexity
O ( n ) time complexity where n is the chars in the string O ( n ) space complexity
string
<not_specific>