2023-09-17 13:16: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 len(self.urls)
def decode(self, shortUrl: str) -> str:
"""Decodes a shortened URL to its original URL.
"""
return self.urls[shortUrl - 1]
# Your Codec object will be instantiated and called as such:
# codec = Codec()
# codec.decode(codec.encode(url))