Substring with Concatenation of All Words
来源:互联网 发布:ubuntu tensorflow 编辑:程序博客网 时间:2024/06/05 15:31
-----QUESTION-----
You are given a string,
For example, given:
S: "barfoothefoobarman"
L: ["foo","bar"]
You should return the indices: [0,9]
.
(order does not matter).
-----SOLUTION-----
class Solution {public: vector<int> findSubstring(string S, vector<string> &L) { string word; int wordLen = L[0].length(); int counter = 0; vector<int> result; map<string,int> mapL; map<string,int> mapS; map<string,int>::iterator itMap; for(int i = 0; i < L.size(); i++) { ++mapL[L.at(i)]; } int last = S.length()-wordLen * L.size()+1; for(int i = 0; i< last; i++) { word = S.substr(i,wordLen); itMap = mapL.find(word); while(itMap!= mapL.end()) { ++mapS[word]; if(mapS[word]>mapL[word]) break; counter+=1; if(counter == L.size()) { result.push_back(i); break; } word = S.substr(i+counter*wordLen,wordLen); itMap = mapL.find(word); } counter = 0; mapS.clear(); } return result; }};
0 0
- LeetCode: Substring with Concatenation of All Words
- LeetCode : Substring with Concatenation of All Words
- LeetCode29: Substring with Concatenation of All Words
- [Leetcode] Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- [LeetCode]Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- LeetCode-Substring with Concatenation of All Words
- [LeetCode] Substring with Concatenation of All Words
- 26 - Substring with Concatenation of All Words
- LeetCode:Substring with Concatenation of All Words
- Leetcode: Substring with Concatenation of All Words
- [LeetCode] Substring with Concatenation of All Words
- leetcode Substring with Concatenation of All Words
- leetcode Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- LeetCode Substring with Concatenation of All Words
- BZOJ 1064 NOI2008 假面舞会 DFS
- Java数字图像处理基础知识 - 必读
- Android手机 Fildder真机抓包
- MyMFC(7-9)对话框 CProp2
- Android开发之ExpandableListView
- Substring with Concatenation of All Words
- MyEclipse中debug用法和MyEclipse 快捷键
- 今天,处女面就这么被阿里廉价的拿走了
- CentOS系统安装MySQL教程
- 伙伴地址
- MyMFC(7-9)对话框 CProp3
- BZOJ 1069: [SCOI2007]最大土地面积
- android 4.2以后js 的问题
- HTML与XHTML区别比较