zoukankan      html  css  js  c++  java
  • 535. Encode and Decode TinyURL

    TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk.

    Design the encode and decode methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.

    public class Codec {
        Map<Integer, String> map = new HashMap<>();
        int i=0;
        public String encode(String longUrl) {
            map.put(i,longUrl);
            return "http://tinyurl.com/"+i++;
        }
        public String decode(String shortUrl) {
            return map.get(Integer.parseInt(shortUrl.replace("http://tinyurl.com/", "")));
        }
    }

    ?鬼

  • 相关阅读:
    套接字(socket)
    网络编程
    面向对象之反射
    面向对象的多态
    面向对象之封装
    面向对象之继承
    面向对象之编程思想
    python中的包
    python中的序列化模块
    正则表达式
  • 原文地址:https://www.cnblogs.com/wentiliangkaihua/p/14541066.html
Copyright © 2011-2022 走看看