LeetCode刷题实战535:TinyURL 的加密与解密
解题
public class Codec {
Mapmap = new HashMap ();
int index = 0;
public String encode(String longUrl) {
map.put(index, longUrl);
return "http://tinyurl.com/" + index++;
}
public String decode(String shortUrl) {
return map.get(shortUrl.charAt(shortUrl.length() - 1) - '0');
}
}
评论