We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d456ffc commit 5554c30Copy full SHA for 5554c30
C++/find-common-characters.cpp
@@ -0,0 +1,25 @@
1
+// Time: O(n * l)
2
+// Space: O(1)
3
+
4
+class Solution {
5
+public:
6
+ vector<string> commonChars(vector<string>& A) {
7
+ vector<int> count(26, numeric_limits<int>::max());
8
+ vector<string> result;
9
+ for (const auto& a : A) {
10
+ vector<int> tmp_count(count.size());
11
+ for (const auto& c : a) {
12
+ ++tmp_count[c - 'a'];
13
+ }
14
+ for (int i = 0; i < count.size(); ++i) {
15
+ count[i] = min(count[i], tmp_count[i]);
16
17
18
19
+ for (auto j = 0; j < count[i]; ++j) {
20
+ result.emplace_back(1, i + 'a');
21
22
23
+ return result;
24
25
+};
0 commit comments