Leetcode-1002 Find Common Characters(查找常用字符)
阿新 • • 發佈:2019-03-03
def mon str code class push sizeof max pan
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 stringaa; 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(查找常用字符)