From 2ab874fb3eb24f6bd5e6e8dc2ec9ca67716edb17 Mon Sep 17 00:00:00 2001 From: "Aniket K. Singh" Date: Sun, 26 Feb 2023 23:33:42 -0500 Subject: [PATCH] 0535-encode-and-decode-tinyurl.java --- java/0535-encode-and-decode-tinyurl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 java/0535-encode-and-decode-tinyurl.java diff --git a/java/0535-encode-and-decode-tinyurl.java b/java/0535-encode-and-decode-tinyurl.java new file mode 100644 index 000000000..56db59a72 --- /dev/null +++ b/java/0535-encode-and-decode-tinyurl.java @@ -0,0 +1,16 @@ +public class Codec { + Map map = new HashMap<>(); + + // Encodes a URL to a shortened URL. + public String encode(String longUrl) { + String key = "gjhgjhg7666"; + map.put(key, longUrl); + return key; + } + + // Decodes a shortened URL to its original URL. + public String decode(String shortUrl) { + return map.get(shortUrl); + + } +}