My Ruby Solution


  • 0
    T
    def group_anagrams(strs)
        anagrams = Hash.new {|h, k| h[k] = []}
        
        strs.each do |str|
            sorted = str.chars.sort
            anagrams[sorted] << str
        end
        
        anagrams.values
    end
    

Log in to reply
 

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