class Solution
{
public:
int countCharacters(vector<string>& words, string chars)
{
int re=0;
int sarray[128]={0};
int charray[128]={0};
int temp;
for(int i=0;i<chars.length();i++)
{
char ch=chars[i];
temp=int(ch);
sarray[temp]=1;
charray[temp]++;
}
for(int i=0;i<words.size();i++)
{
bool flag=true;
int once[128]={0};
for(int j=0;j<words[i].length();j++)
{
once[int(words[i][j])]++;
if(sarray[int(words[i][j])]==0||once[int(words[i][j])]>charray[int(words[i][j])])
{
flag=false;
break;
}
}
if(flag)
{
re=re+words[i].length();
}
}
return re;
}
};
题目倒是不难,很快就出思路了:利用两个标志数组,分别检测字母表里面有没有某个字符、某个字符有几个。
但是我却做了接近半个小时,因为我开始的时候没有读明白题就开始做了,而且是两次。读错了两次题意。
刷题的时候变得浮躁了起来,每次大概读一遍题意就开始做了,于是乎经常做完了再改,不如养成慢审题快答题的习惯,这不是应试教育安家立命的本领嘛hhh。
读题花的时间远远少于理解错了题意debug/修改思路的时间!!!