My Ruby Solution


  • 0
    T
    def group_anagrams(strs)
        anagrams = {}
        
        strs.each do |str|
            sorted = str.chars.sort
            if anagrams[sorted]
                anagrams[sorted] << str
            else
                anagrams[sorted] = [str]
            end
        end
        
        anagrams.values
    end
    

Log in to reply
 

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