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 };
水题,没啥好说的
原文地址:https://www.cnblogs.com/Asurudo/p/10464596.html
时间: 2024-10-13 22:23:18