Skip to content

Commit 0cb60bf

Browse files
author
lightmen
committed
modify encode-and-decode-tinyurl.py
1 parent fff2772 commit 0cb60bf

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

python/hash-table/encode-and-decode-tinyurl.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class Codec:
22
def __init__(self):
3-
self.ltos = {}
4-
self.stol = {}
3+
self.d = {}
54
self.s = '0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM'
65

76
def spliturl(self, url):
@@ -13,7 +12,7 @@ def getshort(self):
1312
short = ""
1413
for i in range(7):
1514
short += random.choice(self.s)
16-
if short not in self.stol:
15+
if short not in self.d:
1716
return short
1817

1918
return ''
@@ -26,8 +25,7 @@ def encode(self, longUrl):
2625
"""
2726
addr, long = self.spliturl(longUrl)
2827
short = self.getshort()
29-
self.stol[short] = long
30-
self.ltos[long] = short
28+
self.d[short] = long
3129
return addr + short
3230

3331
def decode(self, shortUrl):
@@ -37,7 +35,7 @@ def decode(self, shortUrl):
3735
:rtype: str
3836
"""
3937
addr, short = self.spliturl(shortUrl)
40-
return addr + self.stol[short]
38+
return addr + self.d[short]
4139

4240
# Your Codec object will be instantiated and called as such:
4341
# codec = Codec()

0 commit comments

Comments
 (0)