1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-03-14 16:22:24 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/TinyURL 的加密与解密 [encode-and-decode-tinyurl].html

39 lines
1.5 KiB
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>TinyURL 是一种 URL 简化服务, 比如:当你输入一个 URL&nbsp;<code>https://leetcode.com/problems/design-tinyurl</code>&nbsp;它将返回一个简化的URL&nbsp;<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>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= url.length &lt;= 10<sup>4</sup></code></li>
<li>题目数据保证 <code>url</code> 是一个有效的 URL</li>
</ul>
</div>
</div>