Skip to content

Commit

Permalink
Time: 33 ms (96.94%), Space: 15.9 MB (87.44%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Dec 2, 2023
1 parent b1209cd commit e062072
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
public:
int countCharacters(vector<string>& words, string chars) {
int charsMap[26] = {0};
int len = 0;
for(auto &ch : chars){
charsMap[ch-'a'] += 1;
}
for(auto &word : words){
int wordCharsMap[26] = {0};
bool consider = true;
for(auto &ch : word){
wordCharsMap[ch-'a'] += 1;
}
for(int i=0;i<26;i++){
if( wordCharsMap[i] > charsMap[i] ){
consider = false;
break;
}
}
if( consider ){
len += word.size();
}
}
return len;
}
};

0 comments on commit e062072

Please sign in to comment.