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. 寒假day22

    今天解决了标签模块的一些错误,同时美化了界面

  2. Python多线程,线程死锁及解决,生产者与消费者问题

    1.Thread类 普通调用 t = Thread(target=test, args=(i,)) # test为目标函数名, 若函数需要参数将其以元组形 # 式赋给args, 若无参数可不写 t.s ...

  3. part12 非核心代码异步加载

    router文件中的 index component: ()=> import(‘path’) // 这样 访问一个页面 就只请求这个页面的js逻辑 //当app很小的的时候不需要做异步拆分 / ...

  4. 项目进度02-Day3

    ①今天做了什么? 数据库数据的重置.之前的用户类字段的补充.简单的平台信息查询 ②明天要做什么?   分类浏览和综合查询功能. ③遇到了什么问题? 出现问题:Parameter index out o ...

  5. bootstrap快速上手

    bootstarp快速上手 首先英文不是非常好无法阅读英文文档的同学的可以翻阅其他团队翻译的官方:http://code.z01.com/ 项目依赖 ,css文件在所有样式之前,js依赖,首先jq,再 ...

  6. Tomcat导入工程

    Windows->Preference->Server->Runtime environment->Add浏览路径(选择Workbench default JRE)

  7. go多态

      package main import ( "fmt" ) type Intf interface { process() } type MsgBase struct { id ...

  8. R语言入门 (有其他编程语言基础)

    慢慢才意识到概率统计的重要性,当时学的时候只知道很重要,是机器学习基础啥的,但是却没有真正意识到( ╯□╰ ).我现在的理解是,统计学习可以从大数据中挖掘出规律(其实和数据挖掘还是很相关的),在科研工 ...

  9. Anaconda 添加清华源与恢复默认源

    1.添加清华源 查看清华大学官方镜像源文档:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/ 本文基于Windows平台,首先用命令: conda ...

  10. Java正则表达式基础知识整理

    指定为字符串的正则表达式必须首先被编译为此类的实例.然后,可将得到的模式用于创建 Matcher 对象,依照正则表达式,该对象可以与任意字符序列匹配.执行匹配所涉及的所有状态都驻留在匹配器中,所以多个 ...