LeetCode题解(1065):字符串的索引对(Python)
发布日期:2021-06-29 20:13:28
浏览次数:3
分类:技术文章
本文共 776 字,大约阅读时间需要 2 分钟。
题目:(简单)
标签:字符串、字典树
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|---|---|---|
Ans 1 (Python) | O ( W + T × L ) O(W+T×L) O(W+T×L) | O ( W + T ) O(W+T) O(W+T) | 48ms (79.59%) |
Ans 2 (Python) | |||
Ans 3 (Python) |
解法一:
class Solution: def indexPairs(self, text: str, words: List[str]) -> List[List[int]]: tree = { } for i, word in enumerate(words): node = tree for ch in word: if ch not in node: node[ch] = { } node = node[ch] node["@"] = i ans = [] for i in range(len(text)): node = tree j = i while j < len(text) and text[j] in node: node = node[text[j]] if "@" in node: ans.append([i, j]) j += 1 return ans
转载地址:https://dataartist.blog.csdn.net/article/details/110730744 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年05月02日 10时54分19秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
python 在爬虫中怎样把数据添加到excle样式中
2019-04-30
Scrapy框架介绍和简单创建使用
2019-04-30
python 爬虫中selenium 爬取数据 csv储存思路加代码
2019-04-30
python 爬虫 网易云音乐 抓取
2019-04-30
Django 项目基础的部署步骤流程
2019-04-30
python 爬取天猫店铺商品评论
2019-04-30
python 斗鱼弹幕的爬取一(selenium)
2019-04-30
使用相对对导入 导包报红问题
2019-04-30
UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 116-117: ordinal not in range
2019-04-30
ModuleNotFoundError: No module named ‘pip‘
2019-04-30
美女图片爬虫实例 全代码 爬虫
2019-04-30
python中时间日期相减并转化为秒
2019-04-30
django中迁移表失败怎么办
2019-04-30
python在得到绝对路径时候 \ 转化/
2019-04-30
python中二维码得生成
2019-04-30
Odoo 14 初级入门学习
2019-04-30