Pythonic Solution


  • 0
    W
    class Solution(object):
        def groupStrings(self, strings):
            from collections import defaultdict
            d = defaultdict(list)
            for s in strings:
                d[self.getKey(s)].append(s)
            return d.values()
            
        def getKey(self, s):
            return tuple((ord(c) - ord(s[0])) % 26 for c in s)

Log in to reply
 

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