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 ...
随机推荐
- 什么是Ajax? (转载于疯狂客的BLOG)
Ajax的定义 Ajax不是一个技术,它实际上是几种技术,每种技术都有其独特这处,合在一起就成了一个功能强大的新技术. Ajax包括: XHTML和CSS,使用文档对象模型(Document Obje ...
- 【剑指offer】面试题24:二叉搜索树的后序遍历序列
题目: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 思路: 递归 注意,主要就是假定数组为空时结果为fa ...
- HDFS文件系统的操作
package com.bank.utils; import java.io.BufferedInputStream;import java.io.BufferedOutputStream;impor ...
- [ES6] Module export
Default export: Default export is easy way to export a function to outside module. //flash-message.j ...
- Nested Class Templates
Templates can be defined within classes or class templates, in which case they are referred to as ...
- LDAP索引及缓存优化
一.设置索引 索引将查找信息和 Directory Server 条目关联起来. Directory Server支持以下几种索引: 1出现索引 (pres) - 列出了具有特定属性的条目,与属性的值 ...
- C# 数学运算符
运算符大致分为如下3类: 一元运算符,处理一个操作符 二元运算符,处理两个操作数 三元运算符,处理三个操作数 大多数运算符都是二元运算符,只有几个一元运算符和一个三元运算符,即条件运算符(条件运算符是 ...
- ASP.net 前台页面通过ID获取控件
asp.net的服务器控件的ID通常只能在服务器端很好的识别,客户端需要通过ClientID获得控件 1.通过js获得 var controlID = "<%=controlID. ...
- MVC 5 下,应用log4net收集异常信息
1.安装log4net. 首先在VS中通过nuget安装logenet,我用的是VS2013,截屏如下:
- WPF单线程定时器 简单实例
//窗体加载完毕 void MyMessageBox_Loaded(object sender, RoutedEventArgs e) { //启动定时期倒计时,多线程计时 //System.Thre ...