-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem1187.cpp
More file actions
32 lines (31 loc) · 903 Bytes
/
problem1187.cpp
File metadata and controls
32 lines (31 loc) · 903 Bytes
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
//probably works but takes way too long and time exceeds
class Solution {
public:
vector<int> findNumOfValidWords(vector<string>& words, vector<string>& puzzles) {
vector<int> answers;
for(int i = 0; i < puzzles.size(); i++){
answers.push_back(findValids(puzzles.at(i), words));
}
return answers;
}
int findValids(string puzzle, vector<string>& words){
int val = 0;
for(int i = 0; i < words.size(); i++){
if(validWord(puzzle, words.at(i))){
val++;
}
}
return val;
}
bool validWord(string p, string w){
if(w.find(p.at(0)) == string::npos){
return false;
}
for(int i = 0; i < w.size(); i++){
if(p.find(w.at(i)) == string::npos){
return false;
}
}
return true;
}
};