LeetCode题解(0535):TinyURL的加密与解密(Python)
发布日期:2021-06-29 20:09:25
浏览次数:2
分类:技术文章
本文共 519 字,大约阅读时间需要 1 分钟。
题目:(中等)
标签:哈希表、数学
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|---|---|---|
Ans 1 (Python) | O ( 1 ) O(1) O(1) | O ( N ) O(N) O(N) | 48ms (40.55%) |
Ans 2 (Python) | |||
Ans 3 (Python) |
解法一:
class Codec: def __init__(self): self.hashmap = { } def encode(self, longUrl: str) -> str: token = str(hash(longUrl)) self.hashmap[token] = longUrl return str(token) def decode(self, shortUrl: str) -> str: if shortUrl in self.hashmap: val = self.hashmap[shortUrl] del self.hashmap[shortUrl] return val
转载地址:https://dataartist.blog.csdn.net/article/details/109836604 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月10日 22时34分50秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
uni-app 环境搭建
2021-07-03
uni-app 浏览器测试
2021-07-03
dom - 12 种 node 类型
2021-07-03
Dart - 环境配置
2021-07-03
Dart - comment 注释
2019-04-30
Dart - variate 变量
2019-04-30
Dart - default 默认值
2019-04-30
Dart - default&const
2019-04-30
Dart - if else
2019-04-30
Dart - 循环控制
2019-04-30
Dart - switch
2019-04-30
Dart - break 和 continue
2019-04-30
Dart - import
2019-04-30
Dart - 类
2019-04-30
Dart - 类的成员变量
2019-04-30
javascript - 严格模式(use strict)
2019-04-30
eslint warnings 与 error
2019-04-30
eslint - for-direction 循环
2019-04-30
eslint - getter-return
2019-04-30