1. 首页
  2. 数据库
  3. 其它
  4. leetcode1160 拼写单词

leetcode1160 拼写单词

上传者: 2021-01-10 15:57:17上传 PDF文件 84.37KB 热度 10次
思路 维护一个容量为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
下载地址
用户评论