当前位置:网站首页>leetcode:30. Concatenate substrings of all words [counter matching + pruning]
leetcode:30. Concatenate substrings of all words [counter matching + pruning]
2022-06-23 16:22:00 【Review of the white speed Dragon King】

analysis
Use one Counter Record words Number of occurrences of
Then record the total length and the length of each word
Began to s Start traversal of
Then look at the s Of the content intercepted in Counter Compliance
Once there is a certain excess, just prune it directly
ac code
class Solution:
def findSubstring(self, s: str, words: List[str]) -> List[int]:
# double pointers
pattern = Counter(words)
n, m, seg, nums = len(s), len(''.join(words)), len(words[0]), len(words)
ans = []
#print(pattern)
for st in range(n - m + 1):
now = s[st: st + m]
c = Counter()
flag = True
for i in range(nums):
c[now[seg*i : seg*(i + 1)]] += 1
if c[now[seg*i : seg*(i + 1)]] > pattern[now[seg*i : seg*(i + 1)]]:
flag = False
break
if not flag:
continue
#print(c)
if c == pattern:
ans.append(st)
return ans
summary
Simple Counter
边栏推荐
- 将vscode打造无敌的IDE(14) tasks.json和launch.json配置详解,随心所欲添加自动化任务
- pytorch:模型的保存与导出
- 批量注册组件
- Apache commons tool class
- Array's own method
- 怎样快速的应对变动的生产管理需求?
- How did Tencent's technology bulls complete the overall cloud launch?
- How can I get the discount for opening a securities account? Is online account opening safe?
- Object
- [openharmony] USB gadget configuration HDC function cfg file interpretation
猜你喜欢

get_ edges

【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)

Detailed explanation of MQ message oriented middleware theory

阻塞、非阻塞、多路复用、同步、异步、BIO、NIO、AIO 一文搞定

How to configure PostgreSQL data source on SSRs page
NLP 论文领读|改善意图识别的语义表示:有监督预训练中的各向同性正则化方法

线程池

Solution: in the verification phase, the first batch does not report errors, and the second batch reports CUDA exceeded errors
![生成二叉搜索平衡树[利用树递归特性]](/img/b3/f8edf45bdfdced7c3698088dbf7d84.png)
生成二叉搜索平衡树[利用树递归特性]
![[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)](/img/6d/8b1ac734cd95fb29e576aa3eee1b33.png)
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)
随机推荐
golang二分查找法代码实现
Sleuth + Zipkin
腾讯的技术牛人们,是如何完成全面上云这件事儿的?
融云:让银行轻松上“云”
js 对象 使用小技巧
Golang对JSON文件的写操作
PageHelper在面对复杂service数据处理下的分页问题
Object
NLP 论文领读|改善意图识别的语义表示:有监督预训练中的各向同性正则化方法
R语言ggplot2可视化水平箱图(Horizontal boxplot with coord_flip)、并添加抖动数据点显示分布情况(jittered points)
PageHelper faces the paging problem of complex service data processing
R语言plotly可视化:plotly可视化在对比条形图中添加误差条(Bar Chart with Error Bars with plotly in R)
matlab: 如何从一些数据里知道是由哪些数据相加得出一个已知数
A tour of grpc:01 - Basic Theory
Web篇_01 了解web开发
npm 如何发包 删包
Improving efficiency or increasing costs, how should developers understand pair programming?
How is it cheaper to open a stock account? Is it safe to open an account online now?
513. Find Bottom Left Tree Value
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)