1044. Find Common Characters
My accepted C++ solution to LeetCode problem 1044, Find Common Characters, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 12.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 12.6MB, accepted 2025-12-27.
class Solution {
public:
vector<string> commonChars(vector<string>& words) {
vector<int> minFreq(26, INT_MAX);
for (auto& word : words) {
vector<int> freq(26, 0);
for (char c : word) freq[c - 'a']++;
for (int i = 0; i < 26; i++) minFreq[i] = min(minFreq[i], freq[i]);
}
vector<string> res;
for (int i = 0; i < 26; i++) {
while (minFreq[i]-- > 0) res.push_back(string(1, 'a' + i));
}
return res;
}
};