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的更多相关文章

  1. [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 ...

  2. 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 ...

  3. 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 ...

  4. 【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 ...

  5. 【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 ...

  6. 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 ...

  7. LeetCode - 30. Substring with Concatenation of All Words

    30. Substring with Concatenation of All Words Problem's Link --------------------------------------- ...

  8. Effective Java 51 Beware the performance of string concatenation

    Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...

  9. 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 ...

随机推荐

  1. CSS3/HTML5实现漂亮的分步骤注册登录表单

    分步骤的登录注册表单现在也比较多,主要是能提高用户体验,用户可以有选择性的填写相应的表单信息,不至于让用户看到一堆表单望而却步.今天和大家分享的就是一款基于HTML5和CSS3的分步骤注册登录表单,外 ...

  2. HDU_1009——老鼠的交易,性价比排序,最大化收益

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  3. Thinkphp中distinct的用法

    Thinkphp中distincat的用法 TP中distinct()的用处主要是去除重复的值 在Thinkphp手册中也详细说明了(链接:http://document.thinkphp.cn/ma ...

  4. thread block grid

    grid里面包含block,block里面包含thread grid里面所有的block都是同样大小的,  每个block最多可以有1024个thread. blockDim表示一个block里面th ...

  5. 尝鲜党:Nexus5、6刷安卓M教程

    说明: 进入recovery的命令:adb reboot recovery 进入bootloader的命令:adb reboot bootloader 概述 F:\Nexus5\AndroidM\ha ...

  6. 减少iOS应用程序安装包大小

    安装包优化大小方法: <资源优化> 1.去除无用资源 通过几次项目的升级后,项目中会出现一些没有用到的图片.这些图片在我们导入到项目中后,之后项目升级过程后并没有再次用到. 那这些图片我们 ...

  7. android studio 更改快捷键为eclipse中习惯的方式

    虽然之前看了不少android studio的快捷键,但主要开发依然还是在eclipse上,仍然不习惯android studio的快捷键方式,今天看一视频说可以改快捷键为eclipse的方式,不由得 ...

  8. Java基础知识强化47:StringBuffer类之StringBuffer的三个面试题

    1. 面试题:String,StringBuffer,StringBuilder的区别 ? 答:String是字符串内容不可变的,而StringBuffer和StringBuilder是字符串内容长度 ...

  9. swift和oc混编

    请参考这篇博客:点击查看

  10. .NET基础拾遗(7)多线程开发基础4

    一.多线程编程中的线程同步 1.C#中的lock关键字 lock关键字可能是我们在遇到线程同步的需求时最常用的方式,但lock只是一个语法糖,为什么这么说呢,下面慢慢道来. (1)lock的等效代码其 ...