Re: [閒聊] 每日leetcode
3223. Minimum Length of String After Operations
## 思路
先計算每個字元的出現次數
AAAAA --> AAA -> A
AAAA --> AA
如果奇數就+1, 偶數+2
## Code
```cpp
class Solution {
public:
int minimumLength(string s) {
int res = 0;
vector<int> count(26, 0);
for (char& ch: s) {
count[ch-'a']++;
}
for (int i=0; i<26; ++i) {
if (count[i] == 0)
continue;
res += (count[i] & 1) ? 1 : 2;
}
return res;
}
};
```
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 86.48.12.134 (日本)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736767476.A.6E0.html
推
01/13 20:32,
11月前
, 1F
01/13 20:32, 1F
推
01/13 23:29,
11月前
, 2F
01/13 23:29, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1272 之 1554 篇):