Concise pythonic solution 5 lines


  • 0
    D
    def groupStrings(self, strings):
        results = {}
        for idx, val in enumerate(strings):
            key = "_"+"_".join(str((ord(val[id+1])- ord(val[id]))%26) for id in range(len(val)-1))
            if key in results:
                results[key].append(val)
            else:
                results[key] = [val]
                    
        return [ val for key,val in results.iteritems()]

Log in to reply
 

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