2023-09-17 13:12:53 +0000 UTC
Encode and Decode TinyURL
Categories:
Links
Code
class Codec:
def __init__(self):
self.urls = []
def encode(self, longUrl: str) -> str:
"""Encodes a URL to a shortened URL.
"""
self.urls.append(longUrl)
return str(len(self.urls) - 1)
def decode(self, shortUrl: str) -> str:
"""Decodes a shortened URL to its original URL.
"""
return self.urls[int(shortUrl)]
# Your Codec object will be instantiated and called as such:
# codec = Codec()
# codec.decode(codec.encode(url))