-
-
Save spreered/b0d7ab1a32d41f5ab8f89e46efca7a58 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
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 |
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
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