고려해보면 좋은 포인트
큰 용량일 때?
https://leetcode.com/discuss/interview-question/124658/Design-a-URL-Shortener-(-TinyURL-)-System/
class Codec:
host = "<http://tinyurl.com>"
stringList= "abcdefghijklmnopqrstuvwxyzABCDEF \
GHIJKLMNOPQRSTUVWXYZ0123456789"
dictionary = {}
def encode(self, longUrl: str) -> str:
"""Encodes a URL to a shortened URL.
"""
length = 6
tinyPath = "".join(random.choices(self.stringList,k=6))
self.dictionary[tinyPath] = longUrl
return tinyPath
def decode(self, shortUrl: str) -> str:
if shortUrl in self.dictionary:
return self.dictionary[shortUrl]
return None
"""Decodes a shortened URL to its original URL.
"""
# Your Codec object will be instantiated and called as such:
# codec = Codec()
# codec.decode(codec.encode(url))
TinyUrl을 Random으로 생성해서 Key-Value 형태로 저장한다
Q. 만약 중복되는 TinyURL이 생긴다면?