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/修改思路的時間!!!