4 Lines Python Beating 98%


  • 1
    R
    class Solution(object):
        def groupStrings(self, strings):
            """
            :type strings: List[str]
            :rtype: List[List[str]]
            """
            # set up a table to store the result
            table = {}
    
            for i in strings:
               num = [ (ord(i[j]) - ord(i[j+1])) % 26 for j in range(len(i)-1) ]
               table.setdefault(str(num), []).append(i)
    
            return table.values()
    

Log in to reply
 

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