参考:https://leetcode.com/problems/find-common-characters/discuss/247573/C%2B%2B-O(n)-or-O(1)-two-vectors

地址:https://leetcode.com/problems/find-common-characters/

  1. vector初始化:vector<int> a(7,3) // 把a初始化为包含7个值为3的int
  2. char转化为string:string(1,ch)
  3. for (auto s : A)
  4. 使用min
class Solution {
public:
vector<string> commonChars(vector<string>& A) {
vector<int> cnt(, INT_MAX);
vector<string> res; for (auto s : A)
{
vector<int> cnt1(, );
for (auto c : s)
cnt1[c - 'a'] ++;
for (auto i = ; i < ; ++i)
cnt[i] = min(cnt[i], cnt1[i]);
} for (auto i = ; i < ; ++i)
for (auto j = ; j < cnt[i]; ++j)
res.push_back(string(, i + 'a'));
return res;
}
};

1002. Find Common Characters查找常用字符的更多相关文章

  1. LeetCode 1002. Find Common Characters (查找常用字符)

    题目标签:Array, Hash Table 题目给了我们一个string array A,让我们找到common characters. 建立一个26 size 的int common array, ...

  2. Leetcode 1002. 查找常用字符

    1002. 查找常用字符  显示英文描述 我的提交返回竞赛   用户通过次数301 用户尝试次数324 通过次数303 提交次数480 题目难度Easy 给定仅有小写字母组成的字符串数组 A,返回列表 ...

  3. 【LEETCODE】43、1002. Find Common Characters

    package y2019.Algorithm.array; import java.util.*; /** * @ProjectName: cutter-point * @Package: y201 ...

  4. [Swift]LeetCode1002. 查找常用字符 | Find Common Characters

    Given an array A of strings made only from lowercase letters, return a list of all characters that s ...

  5. 力扣(LeetCode)1002. 查找常用字符

    给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表.例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 ...

  6. 1002. 查找常用字符 leecode

    题目: 给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表.例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该 ...

  7. 【leetcode】1002. Find Common Characters

    题目如下: Given an array A of strings made only from lowercase letters, return a list of all characters ...

  8. 【LeetCode】1002. Find Common Characters 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...

  9. 查找常用字符(给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。)

    给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表. 例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 ...

随机推荐

  1. Kafka、RabbitMQ、RocketMQ等消息中间件的对比

    Kafka 是LinkedIn开源的分布式发布-订阅消息系统,目前归属于Apache定级项目.Kafka主要特点是基于Pull的模式来处理消息消费,追求高吞吐量,一开始的目的就是用于日志收集和传输.0 ...

  2. QT中QLineEdit的editingFinished()信号在按下回车时会触发两次的解决办法

    class MyLineEdit : public QLineEdit { Q_OBJECT public: MyLineEdit(QWidget * parent = 0) : QLineEdit( ...

  3. 2nd,Python基础2——02

    1 列表.元组操作 列表可以对数据实现最方便的存储.修改等操作 names = ['Jack', 'Leon','Eric'] 通过下表访问列表中的元素,下标从0开始计数 names = ['Jack ...

  4. hdu 6169 Senior PanⅡ Miller_Rabin素数测试+容斥

    Senior PanⅡ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Pr ...

  5. Missing artifact com.oracle:ojdbc6:jar:10.2.0.4.0问题解决 ojdbc包pom.xml出错

    遇到的问题:ojdbc.jar包出错 原因:因为oracle的ojdbc.jar是收费的,所以maven的中央仓库中没有这个资源,只能通过配置本地库才能加载到项目中去. 解决办法: (前提是安装好了m ...

  6. [转][osg][QT]osg与QT界面结合的简单例子

    //QT += core gui opengl //LIBS += -losgViewer -losgDB -losgUtil -losg -lOpenThreads -losgGA -losgQt ...

  7. 求文件的hash值(基于SHA3的Hash)

    import hashlib import tkinter from tkinter import filedialog import pyperclip def fileHash(fileName) ...

  8. 离线人脸识别C#类库分享 虹软2.0版本

    目前只封装了人脸检测部分的类库,供大家交流学习,肯定有问题,希望大家在阅读使用的时候及时反馈,谢谢!使用虹软技术开发完成 戳这里下载SDKgithub:https://github.com/dayAn ...

  9. NGUI实现的一套不同大小 Item 的循环滚动代码

    测试: 数据 & Item  的 Ctrl : using UnityEngine; public class ScrollViewItemData { public int index; p ...

  10. Spring Boot入门第一天:Hello, Spring Boot!

    原文链接 1. 新建一个Maven Web项目. 2. 配置pom.xml文件. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...