Skip to content

Commit

Permalink
Create 1160. Find Words That Can Be Formed by Characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 2, 2023
1 parent e009605 commit 695ece0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 1160. Find Words That Can Be Formed by Characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public:
int countCharacters(vector<string>& words, string chars) {
int ans = 0;
map<char, int> ss;
for(int i = 0; i < chars.length(); i++)
ss[chars[i]]++;
for(int i = 0; i < words.size(); i++)
{
int count = 0;
map<char, int> mp = ss;
for(int j = 0; j < words[i].length(); j++)
{
if((mp.find(words[i][j]) != mp.end()) && mp[words[i][j]] != 0){
mp[words[i][j]]--;
count++;
}
}
if(count == words[i].length())
ans += count;
}
return ans;
}
};

0 comments on commit 695ece0

Please sign in to comment.