2023-12-09 18:42:21 +08:00
|
|
|
|
<p>TinyURL 是一种 URL 简化服务, 比如:当你输入一个 URL <code>https://leetcode.com/problems/design-tinyurl</code> 时,它将返回一个简化的URL <code>http://tinyurl.com/4e9iAk</code> 。请你设计一个类来加密与解密 TinyURL 。</p>
|
2022-03-27 20:52:13 +08:00
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>加密和解密算法如何设计和运作是没有限制的,你只需要保证一个 URL 可以被加密成一个 TinyURL ,并且这个 TinyURL 可以用解密方法恢复成原本的 URL 。</p>
|
|
|
|
|
|
|
|
|
|
<p>实现 <code>Solution</code> 类:</p>
|
|
|
|
|
|
|
|
|
|
<div class="original__bRMd">
|
|
|
|
|
<div>
|
|
|
|
|
<ul>
|
|
|
|
|
<li><code>Solution()</code> 初始化 TinyURL 系统对象。</li>
|
|
|
|
|
<li><code>String encode(String longUrl)</code> 返回 <code>longUrl</code> 对应的 TinyURL 。</li>
|
|
|
|
|
<li><code>String decode(String shortUrl)</code> 返回 <code>shortUrl</code> 原本的 URL 。题目数据保证给定的 <code>shortUrl</code> 是由同一个系统对象加密的。</li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
<strong>输入:</strong>url = "https://leetcode.com/problems/design-tinyurl"
|
|
|
|
|
<strong>输出:</strong>"https://leetcode.com/problems/design-tinyurl"
|
|
|
|
|
|
|
|
|
|
<strong>解释:</strong>
|
|
|
|
|
Solution obj = new Solution();
|
|
|
|
|
string tiny = obj.encode(url); // 返回加密后得到的 TinyURL 。
|
|
|
|
|
string ans = obj.decode(tiny); // 返回解密后得到的原本的 URL 。
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li><code>1 <= url.length <= 10<sup>4</sup></code></li>
|
|
|
|
|
<li>题目数据保证 <code>url</code> 是一个有效的 URL</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|