Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class Codec {
  2. private ArrayList<String> urls = new ArrayList<String>();
  3. // Encodes a URL to a shortened URL.
  4. public String encode(String longUrl) {
  5. urls.add(longUrl);
  6. return String.valueOf(urls.size() - 1);
  7. }
  8.  
  9. // Decodes a shortened URL to its original URL.
  10. public String decode(String shortUrl) {
  11. int idx = Integer.valueOf(shortUrl);
  12. return idx > urls.size() ? "" : urls.get(idx);
  13. }
  14. }
  15.  
  16. // Your Codec object will be instantiated and called as such:
  17. // Codec codec = new Codec();
  18. // codec.decode(codec.encode(url));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement