bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 535. Encode and Decode TinyURL

535. Encode and Decode TinyURL

Leetcode Solutions

Approach # Using Simple Counter

  1. Initialize a counter and a HashMap.
  2. For each call to encode, increment the counter.
  3. Convert the counter to a string and append it to a base short URL.
  4. Store the mapping of the short URL to the long URL in the HashMap.
  5. For each call to decode, look up the short URL in the HashMap and return the corresponding long URL.
UML Thumbnail

Approach # Random fixed-length encoding

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...