Skip to content

Instantly share code, notes, and snippets.

@spreered

spreered/is_anagram1.rb Secret

Created Sep 13, 2017
Embed
What would you like to do?
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