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. rsyslog 直接kill进程,在重新启动会全部发送日志

    <pre name="code" class="html">jrhapt11:/root# ps -ef | grep rsyslog root 8 ...

  2. 【转】三星8552 手机提示升级系统 完成后重启 开机画面一直停留在三星的LOGO 一闪一闪 怎么办

    原文网址:http://ask.zol.com.cn/q/309501.html 楼主你好,手机出现这种情况的话,可以先将电池取下来重新安装,如果不能的话,可以在关机状态下按住电源键+音量下键之后进入 ...

  3. Codeforces 235E Number Challenge

    http://codeforces.com/contest/235/problem/E 远距离orz......rng_58 证明可以见这里(可能要FQ才能看到) 还是copy一下证明吧: 记 $$f ...

  4. window.open的小技巧分享

        今天再次谈起window.open是因为发现了一个比较好玩的小技巧,详细内容我们稍后详细说明.       聊到window.open,不得不说明一下他的使用方法,主要有两种形式:   win ...

  5. JS浏览器对象-Location对象

    1.返回web主机的域名 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  6. wpf下拉框不能多选的原因

    <dxe:ComboBoxEdit Margin="0"  Height="25" Width="65" VerticalAlignm ...

  7. (转)linux bash shell 入门教程

    Shell Script(bash)简介 众所皆知地,UNIX上以小工具著名,利用许多简单的小工具,来完成原本需要大量软体开发的工作,这一点特色,使得UNIX成为许多人心目中理想的系统平台. 在众多的 ...

  8. StringBuffer学习笔记

    StringBuffer是什么? StringBuffer是使用缓冲区的,本身也是操作字符串的,它是一个具体的操作类.与String类不同的是,它其中的内容是可以改变的.它不能像String那样采用直 ...

  9. How to get multi-touch working(Linux and Andriod)

    1.在hid-ids.h中加入vid pid           2.在hid-multitouch..c->mt_devices[] 中加入          {                ...

  10. Word02-隐藏回车换行符

    Word文档中每次输入回车后,会显示一个换行标志符,影响页面显示效果. 如下图,换行符隐藏前后: 设置方法:(选项-->显示-->段落标记前面的√去掉即可)