Skip to content

Instantly share code, notes, and snippets.

@spreered
Created September 13, 2017 07:51
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 spreered/b0d7ab1a32d41f5ab8f89e46efca7a58 to your computer and use it in GitHub Desktop.
Save spreered/b0d7ab1a32d41f5ab8f89e46efca7a58 to your computer and use it in GitHub Desktop.
def is_anagram(s, t)
a1 = s.each_char.to_a
a1 = a1.sort
a2 = t.each_char.to_a
a2 = a2.sort
puts a1
puts a2
return a1==a2
end
def is_anagram(s, t)
strComp = Hash.new(0)
i=0
if s.length == t.length
while i<s.length
strComp[s[i]] +=1
strComp[t[i]] -=1
i=i+1
end
return strComp.all? { |index,value| value == 0}
end
false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment