Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Codec {
- private ArrayList<String> urls = new ArrayList<String>();
- // Encodes a URL to a shortened URL.
- public String encode(String longUrl) {
- urls.add(longUrl);
- return String.valueOf(urls.size() - 1);
- }
- // Decodes a shortened URL to its original URL.
- public String decode(String shortUrl) {
- int idx = Integer.valueOf(shortUrl);
- return idx > urls.size() ? "" : urls.get(idx);
- }
- }
- // Your Codec object will be instantiated and called as such:
- // Codec codec = new Codec();
- // codec.decode(codec.encode(url));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement