Leetcode:
1160. Find Words That Can Be Formed by Characters
You are given an array of strings words and a string chars.
A string is good if it can be formed by characters from chars (each character can only be used once).
Return the sum of lengths of all good strings in words.
对于多个字符串以及一个给定的字符,找到能够用给定的字符组成的字符串,并返回所有这样的字符串中字符的总数。
代码如下:
class Solution {
public:
int countCharacters(vector<string>& words, string chars) {
map<char,int>ma;
int length = chars.length();
int size = words.size();
int i,j,k,sum=0;
for(i=0;i<size;i++)
{
ma.clear();
for(k=0;k<length;k++)