leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1002.cpp (661B)


0 class Solution {
1 public:
2 vector<string> commonChars(const vector<string> &words) const {
3 static unsigned count[26];
4 vector<string> res;
6 memset(count, 0xFF, sizeof(count));
7 for (const auto &word : words) {
8 unsigned lcount[26] = {0};
9 for (const char c : word)
10 lcount[c - 'a']++;
11 for (int i = 0; i < 26; i++)
12 count[i] = min(count[i], lcount[i]);
13 }
15 for (int i = 0; i < 26; i++) {
16 const string c(1, 'a' + i);
17 for (int j = 0; j < count[i]; j++)
18 res.push_back(c);
19 }
21 return res;
22 }
23 };