leetcode 5978. 统计追加字母可以获得的单词数

 1 class Solution {
 2 public:
 3     int wordCount(vector<string>& startWords, vector<string>& targetWords) {
 4         int n=startWords.size(),ans=0;
 5         unordered_set<int>mp;
 6         for(auto &p:startWords)
 7         {
 8             int mask=0;
 9             for(auto &ch:p)mask|=(1<<(ch-'a'));
10             mp.insert(mask);
11         }
12         for(auto &p:targetWords)
13         {
14             int mask=0;
15             for(auto &ch:p)mask|=(1<<(ch-'a'));
16             for(auto &ch:p)
17             {
18                 if(mp.find(mask^(1<<(ch-'a')))!=mp.end())
19                 {
20                     ans++;
21                     break;
22                 }
23             }
24         }
25         return ans;
26     }
27 };

 

上一篇:智能指针遇到的一些解答


下一篇:fiex布局常用属性介绍