leetcode_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].
class Solution {
public:
vector<int> findSubstring(string S, vector<string> &L) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
map<string, int> words;
map<string, int> count;
vector<int> res;
if(L.size() == || S.length() < L[].size()*L.size() ) return res;
for(int i = ; i< L.size(); ++i){
++words[L[i]];
}
for(int i= ; i <= S.length()- L[].size()*L.size(); ++i)
{
count.clear();
int j;
for(j = ; j <L.size();++j){
string str = S.substr(i+j*L[].size(), L[].size());
if(words.find(str) == words.end()) break;
count[str]++;
if(count[str] > words[str]) break;
}
if(j == L.size())
res.push_back(i);
}
return res;
}
};
leetcode_Substring with Concatenation of All Words的更多相关文章
- [LeetCode] 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
You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...
- 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
Substring with Concatenation of All Words You are given a string, S, and a list of words, L, that ar ...
- 【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 ...
- LeetCode:Substring with Concatenation of All Words (summarize)
题目链接 You are given a string, S, and a list of words, L, that are all of the same length. Find all st ...
- LeetCode - 30. Substring with Concatenation of All Words
30. Substring with Concatenation of All Words Problem's Link --------------------------------------- ...
- Effective Java 51 Beware the performance of string concatenation
Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...
- 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 ...
随机推荐
- app后端设计--总目录
做了3年app相关的系统架构,api设计,先后在3个创业公司中工作,经历过手机网页端,android客户端,iphone客户端,现就职于app云后端平台bmob(想了解bmob点击这里).其中的乐与苦 ...
- 【KMP】Number Sequence
KMP算法 KMP的基处题目,数字数组的KMP算法应用. 主要是next[]数组的构造,next[]存储的是字符的当前字串,与子串前字符匹配的字符数. 移动位数 = 已匹配的字符数 - 对应的部分匹配 ...
- BootStrap--模态框中 上传图片
问题:在模态框中添加图片并不会得到你上传图片的名称,无法存到数据 下面介绍两个方法,都是可以得到图片名称的. 第一种 前面如何加载模态框就不写了,上篇有写,这里只是为得到图片写的 //需要添加一个 ...
- 【IIS小技巧】将IIS Express改成可以通过ip地址访问
通过浏览器访问的是localhost,如果通过手机访问则需要用ip地址,所以要修改IIS Express的配置,允许通过ip地址访问. IIS Express的配置文件默认在C:\Users\User ...
- firefox关于about:config的常用配置
about:config是火狐的设置页面,火狐提供了不少高级设置选项在这里以便让你可以更加详细地控制火狐的运行方式.(官方不推荐用户手工修改about:config的设置.所以,如果你对于你想修改的内 ...
- chmod
0表示没有权限,1表示可执行权限,2表示可写权限,4表示可读权限数字与字符对应关系如下:r=4,w=2,x=1若要rwx属性则4+2+1=7若要rw-属性则4+2=6:若要r-x属性则4+1=5命令: ...
- easyui-form添加自定义表单验证
easyui自定义表单验证规则其实不是很复杂,只要重写一下重写 $.fn.validatebox.defaults.rules 自定义示例 $.extend($.fn.validatebox.defa ...
- 如何学习javascript?(转)
推荐几本好书: Step 1: <JavaScript DOM编程艺术> 看这本书之前,请先确认您对Javascript有个基本的了解,应该知道if else之类的语法,如果不懂,先去看看 ...
- 腾讯RTX登录提示失败问题及处理办法
出现问题时图片: 解决步骤: 首先ping一下RTX管理器所在的的ip地址 telnet一下服务器的端口 8000,8010 是否能通. 具体操作: 在无法登陆的客户端电脑上开始-运行-输入cmd 确 ...
- out返回值的用法与用途
static void Main(string[] arr) { Console.WriteLine("请输入用户名"); string uname = Console.ReadL ...