Leetcode-916 Word Subsets(单词子集)

 1 class Solution
 2 {
 3     public:
 4         vector<string> wordSubsets(vector<string>& A, vector<string>& B)
 5         {
 6             int hash[28];
 7             int hash2[28];
 8             memset(hash,0,sizeof(hash));
 9             for(auto s:B)
10             {
11                 memset(hash2,0,sizeof(hash2));
12                 for(auto c:s)
13                 {
14                     hash2[c-'a'] ++;
15                     if(hash2[c-'a'] > hash[c-'a'])
16                         hash[c-'a'] = hash2[c-'a'];
17                 }
18             }
19             
20             memset(hash2,0,sizeof(hash2));
21             vector<string> result;
22             int flag = 1;
23             for(auto s:A)
24             {
25                 flag = 1;
26                 memset(hash2,0,sizeof(hash2));
27                 for(auto c:s)
28                 {
29                     hash2[c-'a'] ++;
30                 }
31                 for(int i = 0 ;i < 28;i ++)
32                 {
33                     if(hash2[i] < hash[i])
34                     {
35                         flag = 0;
36                         break;
37                     }
38                 }
39                 if(flag)
40                     result.push_back(s);
41             }
42             return result;
43         }
44 };

 

转载于:https://www.cnblogs.com/Asurudo/p/9728902.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值