You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
단순히 입력받는 것을 리턴해도 통과가 된다... 하지만 아무 의미가 없으니 간단하게 짜보자.
간단하게 하는 방법으로 id 카운터 값을 놓고 1씩 증가하면서 shorturl을 생성할 수 있다. map으로 관리해주면 매우 간단하게 가능하다.
Source Code
classCodec:
def__init__(self):
self.url_map= {}
self.url_id=0defencode(self, longUrl: str) ->str:
"""Encodes a URL to a shortened URL. """self.url_id+=1short_url="http://tinyurl.com/"+str(self.url_id)
self.url_map[short_url] =longUrlreturnshort_urldefdecode(self, shortUrl: str) ->str:
"""Decodes a shortened URL to its original URL. """returnself.url_map[shortUrl]
# Your Codec object will be instantiated and called as such:# codec = Codec()# codec.decode(codec.encode(url))
This discussion was converted from issue #55 on September 15, 2026 11:03.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/encode-and-decode-tinyurl/
Problem Summary
tinyurl 같은 것을 구현하는 문제.
Solution
... medium 치고 너무 쉬운데... 그냥 daily 라서 풀어보았다.
단순히 입력받는 것을 리턴해도 통과가 된다... 하지만 아무 의미가 없으니 간단하게 짜보자.
간단하게 하는 방법으로 id 카운터 값을 놓고 1씩 증가하면서 shorturl을 생성할 수 있다. map으로 관리해주면 매우 간단하게 가능하다.
Source Code
All reactions