Skip to content

Commit 023c10d

Browse files
authored
Update strings-differ-by-one-character.py
1 parent 09e7911 commit 023c10d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Python/strings-differ-by-one-character.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ def differByOne(self, dict):
1111
:rtype: bool
1212
"""
1313
MOD, P = 10**9+7, 113
14+
1415
hashes = [0]*len(dict)
15-
for i in xrange(len(dict)):
16-
for j in xrange(len(dict[0])):
17-
hashes[i] = (P*hashes[i] + (ord(dict[i][j])-ord('a'))) % MOD
16+
for i, word in enumerate(dict):
17+
for c in word:
18+
hashes[i] = (P*hashes[i] + (ord(c)-ord('a'))) % MOD
19+
1820
base = 1
1921
for p in reversed(xrange(len(dict[0]))):
2022
lookup = collections.defaultdict(list)

0 commit comments

Comments
 (0)