Leetcode-1002 Find Common Characters(查找常用字符)

Posted Asurudo Jyo の 倉 庫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-1002 Find Common Characters(查找常用字符)相关的知识,希望对你有一定的参考价值。

 1 #define pb push_back
 2 #define maxSize 3939
 3 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
 4 
 5 const int N = 101;
 6 class Solution
 7 {
 8     public:
 9         vector<string> commonChars(vector<string>& A)
10         {
11             int hash[N][N]; 
12             memset(hash,0,sizeof(hash));
13             
14             int sz = A.size();
15             _for(i,0,sz)
16             {
17                 _for(j,0,A[i].size())
18                 {
19                     hash[i][A[i][j]-a] ++;
20                 }
21             }
22             
23             vector<string> rnt;
24             for(int i = 0;i < 26;i ++)
25             {
26                 int mm = INT_MAX;
27                 for(int j = 0;j < sz;j ++)
28                 {
29                     mm = min(mm,hash[j][i]);
30                 }
31                 char aaa = a+i;
32                 string aa;
33                 aa += aaa;
34                 for(int j = 0;j < mm;j ++)
35                 {
36                     rnt.push_back(aa);
37                 }
38             }
39             return rnt;
40         }
41 };

水题,没啥好说的

以上是关于Leetcode-1002 Find Common Characters(查找常用字符)的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode --- 1002. Find Common Characters 解题报告

Golang语言LeetCode 1002. Find Common Characters

LeetCode.1002-寻找共有字符(Find Common Characters)

Leetcode-1002 Find Common Characters(查找常用字符)

leetcode 1002. 查找常用字符(Find Common Characters)

[JavaScript 刷题] 哈希表 - 查找共用字符, leetcode 1002