diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/encode_decode_tinyurl.cpp | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/encode_decode_tinyurl.cpp')
-rw-r--r-- | other/encode_decode_tinyurl.cpp | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/other/encode_decode_tinyurl.cpp b/other/encode_decode_tinyurl.cpp deleted file mode 100644 index d7b9d98..0000000 --- a/other/encode_decode_tinyurl.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// 535. Encode and Decode TinyURL -#include "leetcode.h" - -/* - * tinyurl is a url shortening service where you enter a url such as - * https://looooooongurl.com and it returns a short url such as - * http://tinyurl.com/4e9iAk. design a class to encode a url and decode a tiny - * url. 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. - */ - -class Solution { -private: - const string charset = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - map<string, string> url_code, code_url; - random_device rd; - -public: - string encode(string longUrl) { - string code; - if (!url_code.count(longUrl)) { - for (int i = 0; i < 6; i++) - code.push_back(charset[rd() % charset.size()]); - url_code.insert(pair<string, string>(longUrl, code)); - code_url.insert(pair<string, string>(code, longUrl)); - } else - code = url_code[longUrl]; - return "http://tinyurl.com/" + code; - } - string decode(string shortUrl) { - if (shortUrl.size() != 25 || !code_url.count(shortUrl.substr(19, 6))) - return ""; - return code_url[shortUrl.substr(19, 6)]; - } -}; - -int main() { - Solution obj; - cout << obj.decode(obj.encode("https://leetcode.com/problems/design-tinyurl")) - << endl; // expect: https://leetcode.com/problems/design-tinyurl -} |