AC Python solution using hash map


  • 2
    def groupStrings(self, strings):
        dic = {}
        for s in strings:
            d = ord(s[0]) - 97
            key = tuple((ord(ch) - d) % 26 for ch in s)
            dic[key] = dic[key]+[s] if key in dic else [s]
        ans = []
        for key in dic:
            dic[key].sort()
            ans.append(dic[key])
        return ans
    
    # 23 / 23 test cases passed.
    # Status: Accepted
    # Runtime: 52 ms
    # 93.62%

Log in to reply
 

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