Skip to content

Commit ee9d7f0

Browse files
authored
Create minimum-length-of-string-after-operations.cpp
1 parent 2a184df commit ee9d7f0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n + 26)
2+
// Space: O(26)
3+
4+
// freq table
5+
class Solution {
6+
public:
7+
int minimumLength(string s) {
8+
vector<int> cnt(26);
9+
for (const auto& x : s) {
10+
++cnt[x - 'a'];
11+
}
12+
return accumulate(cbegin(cnt), cend(cnt), 0, [](const auto& accu, const auto& x) {
13+
return accu + (x ? 2 - x % 2 : 0);
14+
});
15+
}
16+
};

0 commit comments

Comments
 (0)