题目:
题解:
class Codec:def __init__(self):self.dataBase = {}def encode(self, longUrl: str) -> str:while True:key = randrange(maxsize)if key not in self.dataBase:self.dataBase[key] = longUrlreturn "http://tinyurl.com/" + str(key)def decode(self, shortUrl: str) -> str:i = shortUrl.rfind('/')key = int(shortUrl[i + 1:])return self.dataBase[key]