LeetCode OJ-- Substring with Concatenation of All Words ***
https://oj.leetcode.com/problems/substring-with-concatenation-of-all-words/
找S中子串,每个元素都在T中出现了,且所有T中元素都在S子串中出现了
class Solution {
public:
vector<int> findSubstring(string S, vector<string> &L) {
vector<int> ans;
if(S.empty() || S.size() == || L.empty() || L.size() == )
return ans;
// L is longer
int len = L.size() * L[].size();
if(len > S.size())
return ans;
unordered_map<string,int> dictL;
for(int i = ; i< L.size(); i++)
dictL[L[i]] += ;
unordered_map<string,int> _dict;
for(int i = ; i + len <= S.size(); i++)
{
string subS = S.substr(i,len);
_dict.clear();
bool flag = true;
for(int j = ; j < len; j+= L[].size())
{
string subLittle = subS.substr(j,L[].size());
if(dictL.find(subLittle) == dictL.end()) //不属于目标里面的
{
flag = false;
break;
}
_dict[subLittle] += ;
if(_dict[subLittle] > dictL[subLittle])
{
flag = false;
break;
}
}
if(flag)
ans.push_back(i);
}
return ans;
}
};
超时、超时、超时、超时……
教训就是,有时候超时不是算法的问题,而是实现的不好。具体看下一篇博客
LeetCode OJ-- Substring with Concatenation of All Words ***的更多相关文章
- [LeetCode] 30. Substring with Concatenation of All Words 解题思路 - Java
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- leetCode 30.Substring with Concatenation of All Words (words中全部子串相连) 解题思路和方法
Substring with Concatenation of All Words You are given a string, s, and a list of words, words, tha ...
- 【leetcode】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 ar ...
- LeetCode - 30. Substring with Concatenation of All Words
30. Substring with Concatenation of All Words Problem's Link --------------------------------------- ...
- LeetCode 030 Substring with Concatenation of All Words
题目要求:Substring with Concatenation of All Words You are given a string, S, and a list of words, L, th ...
- [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 sta ...
- 【leetcode】Substring with Concatenation of All Words (hard) ★
You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...
- Java for LeetCode 030 Substring with Concatenation of All Words【HARD】
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- Java [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 a ...
- [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 sta ...
随机推荐
- Python知识点进阶——细节问题
int()强制转换浮点数 在int()的强制转换浮点数时候,不管是正数还是负数,只取整数部分. 注意:这里不是向上或者向下取整,也不是四舍五入. 无限递归 递归是为了将问题简化为更小规模的同类型问题, ...
- stm32-IIC读写EEPROM—时序说明
I2C 通讯协议:(Inter-Integrated Circuit)是由Phiilps 公司开发的,由于它引脚少,硬件实现简单,可扩展性强,不需要USART.CAN 等通讯协议的外部收发设备,现在 ...
- GIt-恢复进度
继续暂存区未完成的实践 经过了前面的实践,现在DEMO版本库应该处于master分支上,看看是不是这样. $ cd /path/to/my/workspace/demo $ git status -s ...
- 创建 PSO
TechNet 库 Windows Server Windows Server 2008 R2 und Windows Server 2008 浏览 Windows Server 技术 Active ...
- RemoteFX
RemoteFX 编辑 RemoteFX是微软在Windows 7/2008 R2 SP1中增加的一项桌面虚拟化技术,使得用户在使用远程桌面或虚拟桌面进行游戏应用时,可以获得和本地桌面一致的效果. 外 ...
- 申请社交平台appkey详细教程
申请社交平台appkey详细教程 大部分app都需要实现分享到微信.微博等社交平台的功能,但是在各个平台上申请appkey是一件很繁琐的事情.现在来分享一个申请社交平台appkey详细教程,在开发过程 ...
- 怎么使用瓦特平台下面的“代码工厂”快速生成BS程序代码
这里说一下怎么使用瓦特平台下面的“代码工厂”快速生成程序代码 使用平台:windows+"visual studio 2010"+"SqlServer2000+" ...
- mvc-自定义视图引擎
//自定义视图引擎的实质是把数据模型(moudle)和模板(View)转换成html页面,输出到客户端public class MyView:IView { string _viewPath; pub ...
- 学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用利用条件运算符的嵌套来完成此题:C表示。
# -*- coding: utf8 -*- # Author:wxq #python 2.7 #题目:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用利用条件运算符 ...
- 软工实践 - 第九次作业 Alpha 冲刺 (1 / 10)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/9949350.html 作业博客:(班级博客本次作业的链接) 组员情况 组员1(队长):白晨曦 ...