zoukankan      html  css  js  c++  java
  • 535 Encode and Decode TinyURL 编码和解码精简URL地址

    详见:https://leetcode.com/problems/encode-and-decode-tinyurl/description/

    C++:

    class Solution {
    public:
    
        // Encodes a URL to a shortened URL.
        string encode(string longUrl)
        {
            url.push_back(longUrl);
            return "http://tinyurl.com/" + to_string(url.size() - 1);
        }
    
        // Decodes a shortened URL to its original URL.
        string decode(string shortUrl) 
        {
            auto pos = shortUrl.find_last_of("/");
            return url[stoi(shortUrl.substr(pos + 1))];
        }
        
    private:
        vector<string> url;
    };
    
    // Your Solution object will be instantiated and called as such:
    // Solution solution;
    // solution.decode(solution.encode(url));
    

     参考:http://www.cnblogs.com/grandyang/p/6562209.html

  • 相关阅读:
    js加入购物车抛物线动画
    mysql模糊查询like/REGEXP
    Servlt入门
    JSON详解
    AJAX技术初级探索
    css与js基础
    JDBC
    数据库
    反射
    网络编程
  • 原文地址:https://www.cnblogs.com/xidian2014/p/8909914.html
Copyright © 2011-2022 走看看