leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0535.cpp (393B)
0 class Solution { 1 unordered_map<string, int> um; 2 vector<string> str; 3 4 public: 5 string encode(const string &longUrl) { 6 if (um.count(longUrl)) return to_string(um[longUrl]); 7 8 um.insert({longUrl, str.size()}); 9 str.push_back(longUrl); 10 return to_string(str.size() - 1); 11 } 12 13 string decode(const string &shortUrl) { return str[stoi(shortUrl)]; } 14 };