1-liners in Ruby


  • 0

    Sorting:

    def is_anagram(s, t)
        s.chars.sort == t.chars.sort
    end
    

    Grouping:

    def is_anagram(s, t)
        s.chars.group_by{|c|c} == t.chars.group_by{|c|c}
    end

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.