当前位置:网站首页>Force buckle 1002 Find common characters
Force buckle 1002 Find common characters
2022-07-07 11:08:00 【Exy-】
class Solution {
public:
vector<string> commonChars(vector<string>& A) {
vector<string> result;
if (A.size() == 0) return result;
int hash[26] = {0}; // It is used to count the minimum frequency of characters in all strings
for (int i = 0; i < A[0].size(); i++) { // Give... The first string hash initialization
hash[A[0][i] - 'a']++;
}
int hashOtherStr[26] = {0}; // Count the frequency of characters except the first string
for (int i = 1; i < A.size(); i++) {
memset(hashOtherStr, 0, 26 * sizeof(int));
for (int j = 0; j < A[i].size(); j++) {
hashOtherStr[A[i][j] - 'a']++;
}
// to update hash, Guarantee hash Li statistics 26 The minimum number of times a character appears in all strings
for (int k = 0; k < 26; k++) {
hash[k] = min(hash[k], hashOtherStr[k]);
}
}
// take hash Count the number of characters , Into output form
for (int i = 0; i < 26; i++) {
while (hash[i] != 0) { // Notice that this is while, Multiple duplicate characters
string s(1, i + 'a'); // char -> string
result.push_back(s);
hash[i]--;
}
}
return result;
}
};
边栏推荐
- What does intermediate software evaluator test
- [recommendation system 01] rechub
- The gun startles the dragon, and the crowd "locks" Zhou Zhi
- Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
- July 10, 2022 "five heart public welfare" activity notice + registration entry (two-dimensional code)
- MPX plug-in
- How to prepare for the advanced soft test (network planning designer)?
- 2021-05-21
- [installation system] U disk installation system tutorial, using UltraISO to make U disk startup disk
- Using tansformer to segment three-dimensional abdominal multiple organs -- actual battle of unetr
猜你喜欢
[actual combat] transformer architecture of the major medical segmentation challenges on the list --nnformer
如何顺利通过下半年的高级系统架构设计师?
【推荐系统 02】DeepFM、YoutubeDNN、DSSM、MMOE
July 10, 2022 "five heart public welfare" activity notice + registration entry (two-dimensional code)
The gun startles the dragon, and the crowd "locks" Zhou Zhi
When do you usually get grades in the soft exam? Online pedaling?
How to prepare for the advanced soft test (network planning designer)?
[recommendation system 01] rechub
2021 summary and 2022 outlook
uniCloud
随机推荐
TypeScript 接口继承
What are the contents of the intermediate soft test, the software designer test, and the test outline?
Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
软考一般什么时候出成绩呢?在线蹬?
软考信息处理技术员有哪些备考资料与方法?
Interprocess communication (IPC)
2021 summary and 2022 outlook
Go-Redis 中间件
Wallhaven壁纸桌面版
【OneNote】无法连接到网络,无法同步问题
Mendeley -- a free document management tool that automatically inserts references into papers
[OneNote] can't connect to the network and can't sync the problem
[machine learning 03] Lagrange multiplier method
[STM32] actual combat 3.1 - drive 42 stepper motors with STM32 and tb6600 drivers (I)
Kitex retry mechanism
变量的解构赋值
[C #] the solution of WinForm operation zoom (blur)
Unity determines whether the mouse clicks on the UI
香橙派OrangePi 4 LTS开发板通过Mini PCIE连接SATA硬盘的操作方法
Go redis Middleware