码迷,mamicode.com
首页 > Web开发 > 详细

535. Encode and Decode TinyURL

时间:2018-05-30 00:21:27      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:str   return   obj   red   style   string   _id   short   ret   

class Solution {
public:
    long max_id = 0;
    unordered_map<long,string> id_long;
    
    // Encodes a URL to a shortened URL.
    string encode(string longUrl) {
        id_long[max_id++] = longUrl;
        return to_string(max_id - 1);
    }

    // Decodes a shortened URL to its original URL.
    string decode(string shortUrl) {
        long id = stol(shortUrl);
        return id_long[id];
    }
};

// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));

 

535. Encode and Decode TinyURL

标签:str   return   obj   red   style   string   _id   short   ret   

原文地址:https://www.cnblogs.com/JTechRoad/p/9108544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!