forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1684.cpp
More file actions
37 lines (27 loc) · 1.01 KB
/
1684.cpp
File metadata and controls
37 lines (27 loc) · 1.01 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
class Solution {
public:
int countConsistentStrings(string allowed, vector<string>& words) {
//array representing all lowercase letters initialized with zero
int lowerCase[26] = {0};
int result = 0;
//iterating over all "allowed" values and incrementing array
//to identify which letters are present
for(auto c : allowed)
lowerCase[c - 'a']++;
for(auto w : words){
bool found = true;
for(auto c : w){
//if a letter in given word has its value as "0" in lowerCase array,
//then we change found to false
if(lowerCase[c - 'a'] == 0){
found = false;
break;
}
}
//for all found = true, the string is consistent
if(found)
result++;
}
return result;
}
};