LeetCode刷题实战535:TinyURL 的加密与解密
程序IT圈
共 1459字,需浏览 3分钟
·
2022-02-26 12:34
解题
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');
}
}
评论