Substring with Concatenation of All Words
来源:互联网 发布:网络本科报名时间 编辑:程序博客网 时间:2024/06/05 00:16
class Solution {public: vector<int> findSubstring(string s, vector<string>& words) { int n = s.size(); int cnt = words.size(); vector<int> ans; if(n<=0 || cnt<=0) return ans; unordered_map<string, int> dict; for(int i=0; i<cnt; i++) { dict[words[i]]++; } int wl = words[0].size(); for(int i=0; i<wl; i++) { int left=i, count=0; unordered_map<string, int> tdict; for(int j=i; j<=n-wl; j+=wl) { string str = s.substr(j,wl); if(dict.count(str)) { tdict[str]++; count++; while(tdict[str]>dict[str]) { string tmp = s.substr(left, wl); tdict[tmp]--; count--; left += wl; } if(count==cnt) { ans.push_back(left); } } else { tdict.clear(); count = 0; left = j+wl; } } } return ans; }};
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
- C#-根据手机号获得相应的信息
- Codeforces Round #382 (Div. 2) 735B - Urbanization
- 统计工作总结——统计图统计表区别
- Codeforces#382(Div. 2) C.Tennis Championship【递推】
- [独家提供][亲自制作]完美ie8绿色中文版版支持win7x64
- Substring with Concatenation of All Words
- SBC在企业IP通信系统中的应用
- 第十三周1
- FlywayException:Validate failed:Migration checksum mismatch
- 51Nod 1119 机器人走方格 V2
- Android开发配置wifi调试教程
- 1002. 写出这个数 (20)
- Mongos 与集群均衡
- js能多个变量同时定义赋值吗?