Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f68dcd

Browse files
Added 30-Substring-with-Concatenation-of-All-Words.cpp
1 parent 7bdf25b commit 4f68dcd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
vector<int> findSubstring(string s, vector<string>& words) {
4+
5+
unordered_map<string,int> mp;
6+
for(string word:words){
7+
mp[word]++;
8+
}
9+
10+
int slen=s.size();
11+
int wlen=words.size();
12+
int len=words[0].size();
13+
14+
vector<int> ans;
15+
for(int i=0;i<slen-wlen*len+1;i++){
16+
string temp=s.substr(i,wlen*len);
17+
unordered_map<string,int> seen;
18+
for(int j=0;j<temp.size();j+=len){
19+
string curr=temp.substr(j,len);
20+
seen[curr]++;
21+
}
22+
if(seen==mp){
23+
ans.push_back(i);
24+
}
25+
}
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
 (0)