思路 维护一个容量为26的数组,遍历字符chars对每个字母计数 之后使用这张计数表,去对照words内每一个单词,遇到对应字母就-1 若遇到0就跳出,并不计算长度。若整个单词遍历完,就记录改单词长度 实现 #include #include using namespace std; class Solution { public: int countCharacters(vector& words, string chars) { int res = 0; int set[26] = {0}; for(auto c: chars) set