This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
List<String> list = new ArrayList<>(); | |
public String encode(String longUrl) { | |
// Encodes a URL to a shortened URL. | |
list.add(longUrl); | |
return String.valueOf(list.size() - 1); | |
} | |
public String decode(String shortUrl) { | |
// Decodes a shortened URL to its original URL. | |
int id = Integer.valueOf(shortUrl); | |
return list.get(id); | |
} | |
} | |
// Your Codec object will be instantiated and called as such: | |
// Codec codec = new Codec(); | |
// codec.decode(codec.encode(url)); |
No comments:
Post a Comment