Skip to content

Commit

Permalink
2019-08-19
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Aug 20, 2019
1 parent 7afae5c commit 62b3127
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 0249.移位字符串分组/0249-移位字符串分组.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution(object):
def groupStrings(self, strings):
"""
:type strings: List[str]
:rtype: List[List[str]]
"""
# O£¨N ^ 2£©
record = collections.defaultdict(list)
for i, word in enumerate(strings):
tmp = tuple()
for j in range(1, len(word)):
num = ord(word[j]) - ord(word[j - 1])
if num < 0:
num += 26
tmp += (j, num)
record[tmp].append(word)

return record.values()

0 comments on commit 62b3127

Please sign in to comment.