[LeetCode30]Substring with Concatenation of All Words

电力电子技术(13)——大功率可控整流电路 目录引言2.6.1 带平衡电抗器的双反星形可控整流电路电路结构的特点接平衡电抗器的原因平衡电抗器使得两组三相半波整流电路同时导电的原理分析谐波分析2.6.2 多重化整流电路概述原理目标1)移相多重联结2)多重联结电路的顺序控制3重晶闸管整流桥顺序控制带平衡电抗器的双反星形可控整流电路(是多重化整流电路的重要形式之一)的特点:适用于低电压、大电流的场合。多重化整流电路的特点:绕组的极性相反的目的:消除直流磁通势如图所示,虽然两组相电流的瞬时值不同,但是平均电流相等而绕组的极性相反,所以直流安匝(电流*匝数)互 阅读详情

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 without any intervening characters.

For example, given:
S: "barfoothefoobarman"
L: ["foo", "bar"]

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

Analysis:

Try to think this problem straightforward:
Say in L there are m strings with length n. 
What string is required to match in S?     A length of m*n string start with each position in S.
What is a match?  In the m*n long string, every string in L appear only once.

So the algorithm is:
Scan every m*n long string start from each position in S, see if all the strings in L have been appeared only once using Map data structure. If so, store the starting position.

Yes, do not consider any DP or DFS solutions, just using the hash map and loop.

注意考虑L中可能含有重复字符串,需要用两个map

c++实现

vector<int> findSubstring(string S, vector<string> &L) {
        map<string, int> expectCount;
    map<string, int> realCount;
    vector<int> result;
    int row = L.size();
    if(row == 0) return result;
    int len = (int)L[0].size();
    for(int i=0; i< L.size(); i++){
        expectCount[L.at(i)]++;
    }
    for(int i=0; i<=(int)S.size()- row*len;i++){
        realCount.clear();
        int j=0;
        for(; j<row; j++){
            string str = S.substr(i+j*len,len);
            if(expectCount.find(str) != expectCount.end()){
                realCount[str]++;
            }else{
                break;
            }
            if(realCount[str]>expectCount[str])
                break;
        }
        if(j == row)
            result.push_back(i);
    }
    return result;
    }


Java实现

public ArrayList<Integer> findSubstring(String S, String[] L) {
        ArrayList<Integer> result = new ArrayList<Integer>();
        int num = L.length;
        int eachLen = L[0].length();
        if(num == 0 || eachLen ==0) return result;
        HashMap<String, Integer> hMap2 = new HashMap<String,Integer>();
    	for(int j=0;j<num;j++){
        	int val = 1;
			if(hMap2.containsKey(L[j])){
        		val = hMap2.get(L[j]);
        		val++;
			}
    		hMap2.put(L[j], val);
    	}
        for(int i=0;i<=S.length()-num*eachLen;i++){
        	HashMap<String, Integer> hMap = new HashMap<String,Integer>();
        	for(int j=0;j<num;j++){
        		hMap.put(L[j], 0);
        	}
        	int k =0 ;
        	while(k<num){
        		String str = S.substring(i+k*eachLen, i+eachLen*(k+1));
        		if(hMap.containsKey(str)){
        			int val = hMap.get(str);
        			hMap.put(str, ++val);
        			if(hMap.get(str)>hMap2.get(str)) break;
        			
        		}else{
        			break;
        		}
        		k++;
        	}
        	if(k == num) result.add(i);
        }
        
        return result;
    }

巨量千川M-API实战:5分钟搞定短视频计划数据自动获取(Python版) 本文详细介绍了如何利用巨量千川M-API和Python快速搭建自动化工具,实现短视频计划数据的自动获取。通过实战代码演示了从环境准备、Token管理到核心数据接口调用的完整流程,帮助电商运营和技术开发者告别手动导出,高效完成数据汇总与分析。 阅读详情

相关推荐

JMeter脚本录制-快速上手篇

有的项目应用场景下,压测时,需要考虑带宽因素,压测不只是压测接口,静态资源也要一起压测。一般来说,静态资源比较多,如果一个个手工去写请求,是比较繁琐的,此时,可以使用Jmeter的脚本录制功能。 步骤1,创建脚本录制模版。 JMeter菜单:文件>模版,下拉选择到Recording,点击“Create”按钮; 填写录制参数: hostToRecord:填写要录制的主机域名,例如,我们这里填入:www.baidu.com schemeToRecord:填写要录制的模式,例如,htt...

软件测试大叔 5734

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

【项目分享】RailTracker: 火车票务数据采集与分析

从12306使用爬虫爬取火车站及车次信息、火车票价 通过本项目,我们将带领访问者手把手完成火车票数据采集、数据清洗、数据集成、可视化的一整个流程!

zhushatong的博客 3344

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

STM32基于软件模拟IIC进行AHT21B温湿度采集

通过学习软件IIC来进行实操AHT21B采集温湿度。

Liu-FE的博客 3700

基于紫光展锐平台的音频调用到hal层逻辑

基于紫光展锐平台的音频调用到hal层逻辑 1、数据流程图 AudioPolicyService和AudioFlinger的创建: 这两个服务都在audioserver中启动,文件路径: frameworks/av/media/audioserver/main_audioserver.cpp 从AudioFlinger和AudioPolicyService的创建,到output的打开,以及AudioFlinger开始往底层写入数据的具体流程如下图: #mermaid-svg-kjHL4XWwkQXN6NdA

weixin_55053963的博客 1355

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

【上海大学计算机组成原理实验报告】七、程序转移机制

学习实现程序转移的硬件机制//掌握堆栈寄存器的使用//手动方式实现子程序调用转移过程//手动方式实现子程序返回转移过程//编程实现`OUT`寄存器交替显示`11`和`55`//若要求`11`和`55`各显示`50`次后停机,应该如何修改程序?//根据实验指导书的相关内容,实验箱系统的程序转移硬件机制在于,当`LDPC`有效时,如果此时`DUBS`上的值就是转移的目标地址,则此目标地址被打入`PC`,从而实现程序的转移;若`LDPC`为`0`是附带条件的,就形成“条件转移”。

HackerKevon的博客 2472

leetcode 30 Substring with Concatenation of All Words

Substring with Concatenation of All Words

GadyPu的专栏 451

uniapp 开发微信小程序请求问题 , 真机调试正常,开发工具正常,但是使用扫码预览接口都是不通的,发布到体验版也是请求失败

uniapp开发小程序体验版接口请求失败(真机可以)

weixin_60408555的博客 3954

电涡流位移测量技术深度解密

电涡流位移传感器凭借非接触测量、高精度(可达纳米级)、强环境适应性(耐高温高压油污)等优势,成为工业精密位移检测的核心技术。其工作原理基于电磁感应:高频磁场在金属靶面感应涡流,通过检测线圈阻抗变化转化为位移信号。应用需注意靶材依赖性(需按实际材料标定)、安装精度及抗干扰措施。广泛应用于磁悬浮轴承、航空发动机、精密制造等领域,实现对微米级位移的可靠监测。

技术工作者 1753

[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

基于YOLO26的实时目标追踪实战:从训练到视频追踪(附完整可视化代码)

核心组合:YOLO26(高精度检测)+ ByteTrack(稳定追踪)是实时目标追踪的最优工业组合,Ultralytics内置集成无需额外开发;训练优化:追踪场景需优先提升检测框精度(增加box损失权重),保证ID稳定性;可视化核心:为每个ID分配唯一颜色、绘制运动轨迹、显示FPS,是落地场景的必备功能;性能调优:轻量化模型+降分辨率+OpenVINO导出,可在边缘设备(如研华工控机)实现实时追踪。这套代码可直接复用到智慧园区、停车场、工业产线等场景,仅需修改park.yaml中的类别和。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 572

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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

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

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

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

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

[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】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

指尖飞舞 3345

leetcode30 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 without any intervening characters. Example 1: Input: s =

qq_27736687的博客 190
上一篇: [LeetCode] Length of last word
下一篇: [LeetCode] Minimum Window Substring
Mavs
博客等级 码龄17年 166粉丝 296原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值