-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path30.cpp
More file actions
executable file
·55 lines (54 loc) · 1.77 KB
/
30.cpp
File metadata and controls
executable file
·55 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<vector>
#include<string>
#include<map>
using namespace std;
class Solution {
public:
vector<int> findSubstring(string s, vector<string>& words) {
string tmp;
vector<int> answer;
std::map<std::string, int> borrow_words;
for (int j = 0; j < words.size(); j++){
if (borrow_words.count(words[j]) == 0)
borrow_words.insert(std::make_pair(words[j],1));
else
borrow_words[words[j]] ++;
}
if (s.compare("") == 0)
return answer;
if (words.size() == 0)
return answer;
int arbi_length = words.size() * words[0].size();
for (int i = 0; i < s.size();i++){
tmp = "";
if (i + arbi_length <= s.length())
tmp = s.substr(i, arbi_length);
std::map<std::string, int> tmpw = borrow_words;
bool flag = true;
if (tmp != ""){
int st = 0;
while (st < tmp.length()){
string now = tmp.substr(st,words[0].size());
st = st + words[0].size();
bool tmpflag = false;
int index = 0;
if (tmpw.count(now) == 1){
map<string,int>::iterator key = tmpw.find(now);
tmpflag = true;
if (tmpw[now] > 1)
tmpw[now] --;
else tmpw.erase(key);
}
else {
flag = false;
break;
}
}
if (flag == true){
answer.push_back(i);
}
}
}
return answer;
}
};