leetcode 1002 查找共用字符
2023-09-27 14:29:24 时间
查找共用字符
class Solution {
public:
vector<string> commonChars(vector<string>& words) {
vector<string> result;
vector<vector<int>> map(words.size() , vector<int>(26,0));
for(int i=0 ; i<words.size() ;i++)
{
for(int j=0 ; j<words[i].size() ;j++)
map[i][words[i][j] - 'a'] += 1;
}
for(int j=0 ; j<26 ;j++)
{
int tmp = INT_MAX;
for(int i=0 ; i<words.size() ;i++)
{
if(map[i][j] == 0 ) break;
tmp = min( tmp, map[i][j]);
if(i==words.size()-1)
{
while(tmp--)
{
string s(1,'a'+j);
result.push_back(s);
}
}
}
}
return result;
}
};
相关文章
- [LeetCode]Integer to Roman
- LeetCode_二叉树_中等_剑指 Offer 26.树的子结构
- LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
- LeetCode_区间问题_中等_1834. 单线程 CPU
- LeetCode·每日一题·777.在LR字符串中交换相邻字符·双指针
- LeetCode·每日一题·面试题 01.02.判断是否互为字符重排·哈希
- LeetCode·3.无重复字符的最长子串·滑动窗口
- LeetCode-111. 二叉树的最小深度(java)
- LeetCode-94. 二叉树的中序遍历(java)
- LeetCode-316. 去除重复字母&&1081.不同字符的最小子序列(Java实现)
- [LeetCode] 195. Tenth Line 第十行
- [LeetCode] 395. Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
- [LeetCode] 451. Sort Characters By Frequency 根据字符出现频率排序
- leetcode 无重复字符的最长子串 python实现
- leetcode 3 无重复字符的最长子串
- leetcode 463 岛屿的周长