Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates).  For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.

You may return the answer in any order.

Example 1:

Input: ["bella","label","roller"]
Output: ["e","l","l"]

Example 2:

Input: ["cool","lock","cook"]
Output: ["c","o"]
class Solution {
public List<String> commonChars(String[] A) {
List<String> res = new ArrayList<>();
if (A == null || A.length == 0) {
return res;
}
int[] lowerCaseArr = new int[26];
for (char c: A[0].toCharArray()) {
lowerCaseArr[c - 'a'] += 1;
}
for (int i = 1; i < A.length; i++) {
int[] curDict = new int[26];
for (char c: A[i].toCharArray()) {
curDict[c - 'a'] += 1;
}
for (int j = 0; j < lowerCaseArr.length; j++) {
lowerCaseArr[j] = Math.min(lowerCaseArr[j], curDict[j]);
}
} for (int i = 0; i < lowerCaseArr.length; i++) {
while (lowerCaseArr[i] > 0) {
res.add(Character.toString((char)(i + 'a')));
lowerCaseArr[i] -= 1;
}
}
return res;
}
}

[LC] 1002. Find Common Characters的更多相关文章

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

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

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

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

  3. 1002. Find Common Characters

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

  4. 【leetcode】1002. Find Common Characters

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

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

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

  6. 1002. Find Common Characters查找常用字符

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

  7. Leetcode 1002. Find Common Characters

    python可重集合操作 class Solution(object): def commonChars(self, A): """ :type A: List[str] ...

  8. Find Common Characters - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Find Common Characters - LeetCode 注意点 不能单纯的以字母出现的次数来判断是否是公共的字母 解法 解法一:将第一个字符串 ...

  9. Write a program that gives count of common characters presented in an array of strings..(or array of

    转自出处 Write a program that gives count of common characters presented in an array of strings..(or arr ...

随机推荐

  1. springboot-jar-web

    预览 与springboot-jar的区别是: 1.pom.xml 将 <dependency> <groupId>org.springframework.boot</g ...

  2. oracle(9) 序列和约束

    序列 SEQUENCE 也是数据库对象之一,作用:根据指定的规则生成一些列数字. 序列通常是为某张表的主键提供值使用. 主键:通常每张表都会有主键字段,该字段的值要求非空且唯一, 使用该字段来确定表中 ...

  3. vue select框change事件

    vue Select 中< :label-in-value="true" @on-change="satusSelect"> satusSelect ...

  4. django 过滤器-查询集-比较运算符-FQ对象-mysql的命令窗口

    """ 返回查询集的方法称为过滤器 all() 返回查询集中所有数据 filter() 返回符合条件的数据 一.filter(键=值) 二.filter(键=值,键=值) ...

  5. 设计模式讲解5:FlyWeight模式源码

    声明:迁移自本人CSDN博客https://blog.csdn.net/u013365635 FlyWeight模式即享元模式.很多文本编辑器中都使用了FlyWeight模式.FlyWeight单词含 ...

  6. 机器学习分布式框架horovod安装 (Linux环境)

    1.openmi 下载安装 下载连接: https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.1.tar.gz 安装命令 1 ...

  7. POJ 1847:Tram

    Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11771   Accepted: 4301 Description ...

  8. 全天候式投资组合(All-weather Portfolio)

    此策略是美国知名对冲基金Bridgewater的负责人Ray Dalio长期研究的成果,其核心观点是将宏观因子,经济情景(economic scenario),和上文中提到的等风险权重(risk pa ...

  9. 【MySQL参数】- query_cache_type

    MySQL为什么要关闭查询缓存 https://blog.csdn.net/liqfyiyi/article/details/50178591 Query cache的优化方法 https://blo ...

  10. 黑马程序员IDEA版JAVA基础班\JavaWeb部分视频\2-10Request和Response\第5节 request登录案例

    用户登录案例需求: 1.编写login.html登录页面 username & password 两个输入框 2.使用Druid数据库连接池技术,操作mysql,day14数据库中user表 ...