leetcode 30 Substring with Concatenation of All Words

题目连接

https://leetcode.com/problems/substring-with-concatenation-of-all-words/  

Substring with Concatenation of All Words

Description

You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly once and without any intervening characters.

For example, given:
s: "barfoothefoobarman"
words: ["foo", "bar"]

You should return the indices: [0,9].
(order does not matter).

根据题意直接模拟(写的很挫跑的很慢QAQ)

class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
        vector<int> res;
        if(s.empty() || words.empty()) return res;
        for(auto &r: words) A[r]++;
        int n = words[0].size(), m = s.size(), k = words.size();
        int len = m - n * k + 1;
        for(int i = 0; i < len; i++) {
            int d = k, j = i;
            B.clear();
            while(d) {
                string temp = s.substr(j, n);
                j += n;
                if(A.find(temp) == A.end()) {
                    break;
                } else {
                    B[temp]++;
                    if(B[temp] > A[temp]) break;
                    d--;
                }
            }
            if(!d) res.push_back(i);
        }
        return res;
    }
private:
    map<string, int> A, B;
};

转载于:https://www.cnblogs.com/GadyPu/p/5598980.html

cdk&java | 分子sdf文件生成 sdf 阅读详情

相关推荐

Qt C++:跨平台开发利器

摘要: Qt C++是基于C++的跨平台开发框架,通过元对象系统、信号槽机制及模块化架构实现"一次编写,多端部署"。核心特性包括: 跨平台能力:覆盖桌面(Windows/macOS/Linux)、移动端(iOS/Android)、嵌入式及WebAssembly; 信号与槽:替代传统回调,实现对象间高效通信; UI组件库:200+预制组件支持QSS样式定制; 工具链:Qt Creator集成开发环境提供可视化设计、调试及多平台编译。 广泛应用于工业控制、车载系统、医疗设备及跨平台应用开发,

2202_75382767的博客 1680

leetcode-30. Substring with Concatenation of All Words

leetcode-30. Substring with Concatenation of All Words题目: 这题其实算不上难题。至少是难题中比较简单的。 基本思路就是由于words中的String的长短是一样的,那这样就有比较简单的解法,就是用i从0开始向右移动,找substring(0,words[0],length())是否包含在words中就好。当然针对每个i都需要新建一个hashset,并将w

千念飞羽的专栏 554

matlab特征提取和分类_SAST Weekly|MATLAB机器学习初探——做个心音分类器

SAST weekly 是由电子工程系学生科协推出的科技系列推送,内容涵盖信息领域技术科普、研究前沿热点介绍、科技新闻跟进探索等多个方面,帮助同学们增长姿势,开拓眼界,每周更新,欢迎关注!欢迎愿意分享知识的同学投稿至 eesast@mail.tsinghua.edu.cn , 期待你的作品!本期的SAST weekly,想跟大家分享一下如何用MATLAB进行初步的机器学习,构建一个正常/...

weixin_36453829的博客 5578

Leetcode1-100: 30. Substring with Concatenation of All Words

Leetcode1-100: 30. Substring with Concatenation of All Words问题描述解题思路代码实现implement 1 brute forceimplement 2 sliding window分析 问题描述 You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(

Y123iwantit的博客 272

OAI数据集申请与实战:从权限获取到医学影像分析应用

本文详细介绍了OAI数据集的申请流程与医学影像分析实战应用。从NDA账户注册、数据下载技巧到骨盆X光关键点检测的完整实现,帮助医学研究者高效利用这一权威骨关节炎数据集。特别分享使用Pei Y标注数据训练U-Net模型的经验,包括预处理、注意力机制优化等实用技巧。

weixin_30275415的博客 478

腾讯游戏安全组件运行异常的全面解决方案

在使用腾讯游戏时,玩家可能会遭遇游戏安全组件运行异常的问题,这不仅影响游戏的正常启动,还可能在游戏过程中引发一系列问题。本文将详细介绍解决腾讯游戏安全组件运行异常的几种方法,帮助玩家重拾游戏乐趣。腾讯游戏安全组件运行异常是一个复杂的问题,可能涉及服务设置、游戏更新、系统环境优化以及硬件与驱动检查等多个方面。最后,希望本文能帮助玩家顺利解决腾讯游戏安全组件运行异常的问题,让玩家能够无忧无虑地享受游戏带来的乐趣。首先,我们需要从系统的服务管理入手,检查与游戏安全组件相关的服务是否正常运行。

nntxthml的博客 5805

LeetCode代码分析——30. Substring with Concatenation of All Words

LeetCode代码分析——30. Substring with Concatenation of All Words You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that...

huanglong0438的专栏 384

Windows系统下com0com虚拟串口安装与驱动签名禁用全攻略

本文详细介绍了在Windows系统下安装com0com虚拟串口工具的全过程,包括驱动签名问题的解决方法。通过禁用驱动程序强制签名,用户可以顺利安装并使用这款开源工具创建虚拟串口对,适用于软件开发测试、硬件调试等场景。文章还提供了验证虚拟串口功能的实用技巧和常见问题解决方案。

weixin_28720573的博客 386

[leetcode]30. Substring with Concatenation of All Words

自己写的乱七八糟的代码,无法解决s或words里有重复的问题 class Solution { public List&lt;Integer&gt; findSubstring(String s, String[] words) { List&lt;Integer&gt; list=new ArrayList&lt;Integer&gt;(); ...

Belle_Chou的博客 94

【ArcGIS Pro微课1000例】0047:深度学习--棕榈树提取全流程

对汤加科洛瓦伊种植园每棵棕榈树的健康状况进行清查和评估,这需要花费大量的时间和劳动力。为简化此过程,将在 ArcGIS Pro 中使用深度学习模型来识别树木,然后根据植被绿度的测量值计算其健康状况。第一步是找到显示汤加科洛瓦伊的影像,该影像具有足够精细的空间和光谱分辨率来识别树木。获得此影像后,将创建训练样本并将其转换为可供深度学习模型使用的格式。为了让模型识别出它的查找任务,需要定义棕榈树的影像,以便识别相似的像素和树木大小。

智慧空间实验室 2205

【Linux0.11代码分析】之 系列文章链接汇总(全)

【Linux0.11代码分析】00 之 系列文章链接汇总(全)

|~~~热爱生活、努力学习的小伙汁~~~| 1449

30. Substring with Concatenation of All Words - 力扣(LeetCode)

题目: 给定一个字符串s和一些长度相同的单词words。找出 s 中恰好可以由words 中所有单词串联形成的子串的起始位置。 注意子串要与words 中的单词完全匹配,中间不能有其他字符,但不需要考虑words中单词串联的顺序。 示例 1: 输入: s = "barfoothefoobarman", words = ["foo","bar"] 输出:[0,9]...

qq_29760277的博客 164

下载MNIST数据集并使用python将数据转换成NumPy数组(源码解析)

下载MNIST数据集并使用python将数据转换成NumPy数组首先来分析init_mnist函数接下来继续分析load_mnist函数实现数据集转换的python脚本的代码显示MNIST图像并确认数据 下载MNIST数据集并将数据转换成NumPy数组的Python脚本里面最重要的就是load_mnist函数,其他项目想要调用数据集的话,就可以调用load_mnist函数,得到一个字典类型的数据,字典的值是一个Numpy数组。 这些过程是如何实现的,现在开始逐字逐句分析源码: 在load_mnist函数中第

及时总结 4265

leetcode (30) Substring with Concatenation of All Words

原题链接:https://leetcode.com/problems/substring-with-concatenation-of-all-words/ 题目:30. Substring with Concatenation of All Words You are given a string, s, and a list of words, words, that are

菜鸟很菜的专栏 433

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

LeetCode 30. Substring with Concatenation of All Words

LeetCode 30. Substring with Concatenation of All Words Solution1: 转载自:http://www.cnblogs.com/grandyang/p/4521224.html,这道题的思路和LeetCode 567. Permutation in String非常像。滑动窗口的思路要牢记啊!! class Solution { pu...

Allenlzcoder的博客 257

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

LeetCode 30 Substring with Concatenation of All Words 解法为Hashmap

Substring with Concatenation of All Words You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concaten

gx262091291的专栏 375

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

LeetCode-30. Substring with Concatenation of All Words

前言 突然一周没刷过题了,有点时间就刷一下题吧,顺便把解题思路记录下来,一个是自己做笔记,一个是给大家一点思路。前面的二十多道以后有时间再补吧,现在刷到了30题,就从这个开始吧! 问题描述 解法一 首先是一种暴力解法,直接遍历所有可能的list,然后看这个list是否满足要求,在验证该list是否满足要求 的时候需要使用到类似hash的数据结构,保证words中的每个元素都被用到过一次,由于其中...

Catcher 270

LeetCode(30)--Substring with Concatenation of All Words

转载自博客 LeetCode30———–Substring with Concatenation of All Words 看题目都有些费劲,要不是看了几组Custom Testcase才知道题意,顺便说一句Custom Testcase这个功能在调试的时候真的非常实用。 题目意思: 给定一个字串不妨称为母串S,和一组单词,他们保存在一个string的顺序容器Words中,并且满足一个条件,

ruosiliu_123的博客 299

[leetcode]-30-Substring with Concatenation of All Words

题目: You are given a string,s, and a list of words,words, that are all of the same length. Find all starting indices of substring(s) insthat is a concatenation of each word inwordsexactly once a...

ljh0302的专栏 617

leetcode 30. Substring with Concatenation of All Words

You are given a string,s, and a list of words,words, that are all of the same length. Find all starting indices of substring(s) insthat is a concatenation of each word inwordsexactly once and wi...

cmy203的博客 149

leetcode 30. Substring with Concatenation of All Words

leetcode  30. Substring with Concatenation of All Words  又一个TLE  : import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; impo

独钓寒江雪 726

[LeetCode30]Substring with Concatenation of All Words

Substring with Concatenation of All Words You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenatio

coder 进阶的专栏 945

【LeetCode】30. Substring with Concatenation of All Words

You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and

一路前行 622

LeetCode(30) Substring with Concatenation of All Words

题目You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and w

指尖飞舞 3344

[leetcode] 30 Substring with Concatenation of All Words

问题描述: You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and

追梦船的专栏 890
上一篇: leetcode 355 Design Twitte
下一篇: leetcode 10 Regular Expression Matching
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值