LeetCode: Encode And Decode Tinyurl Solution

1/**
2 * Encodes a URL to a shortened URL.
3 *
4 * @param {string} longUrl
5 * @return {string}
6 */
7var encode = function (longUrl) {
8 return Buffer.from(longUrl).toString("base64")
9}
10
11/**
12 * Decodes a shortened URL to its original URL.
13 *
14 * @param {string} shortUrl
15 * @return {string}
16 */
17var decode = function (shortUrl) {
18 return Buffer.from(shortUrl, "base64").toString()
19}
20
21/**
22 * Your functions will be called as such:
23 * decode(encode(url));
24 */

Comments

Loading comments...

Tags

leetcode

Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.

Next Post

LeetCode: Best Time To Buy And Sell Stock With Transaction Fee

Mar 17, 2021

HoningJS

Search Posts