[LC] 1002. Find Common Characters
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的更多相关文章
- 【LEETCODE】43、1002. Find Common Characters
package y2019.Algorithm.array; import java.util.*; /** * @ProjectName: cutter-point * @Package: y201 ...
- LeetCode 1002. Find Common Characters (查找常用字符)
题目标签:Array, Hash Table 题目给了我们一个string array A,让我们找到common characters. 建立一个26 size 的int common array, ...
- 1002. Find Common Characters
Given an array A of strings made only from lowercase letters, return a list of all characters that s ...
- 【leetcode】1002. Find Common Characters
题目如下: Given an array A of strings made only from lowercase letters, return a list of all characters ...
- 【LeetCode】1002. Find Common Characters 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...
- 1002. Find Common Characters查找常用字符
参考:https://leetcode.com/problems/find-common-characters/discuss/247573/C%2B%2B-O(n)-or-O(1)-two-vect ...
- Leetcode 1002. Find Common Characters
python可重集合操作 class Solution(object): def commonChars(self, A): """ :type A: List[str] ...
- Find Common Characters - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Find Common Characters - LeetCode 注意点 不能单纯的以字母出现的次数来判断是否是公共的字母 解法 解法一:将第一个字符串 ...
- 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 ...
随机推荐
- js保留的关键字
js保留的关键字 break else new var case finally return void catch for switch while continue function this w ...
- 在Azure Storage 托管HTTP静态网站
本文演示了在Azure Storage托管HTTP静态网站. 注意:HTTP已经不建议使用. 创建Azure StorageV2 存储账户 账户类型选择“StorageV2(通用版V2)”: 本例中, ...
- [Python Cookbook]Pandas: How to increase columns for DataFrame?Join/Concat
1. Combine Two Series series1=pd.Series([1,2,3],name='s1') series2=pd.Series([4,5,6],name='s2') df = ...
- iview checkbox demo(文档改写)
<template> <div class="content"> <div style="border-bottom: 1px solid ...
- MySQL--数据导入
参考:http://blog.csdn.net/jyb2014/article/details/39294879?locationNum=13 可导入大文件. source 导入总是失败.
- Lyft、Uber、滴滴涉足汽车租赁领域,能打破既有汽车所有权模式吗?
自共享经济出现之后,众多相关项目遍地开花.这些共享经济项目对于人们来说,最直观的感受就是实惠.性价比高.方便.不过抛开这些使用层面的优点来看的话,共享经济项目最大的特色或许就是改变了事物的所有权.一件 ...
- mqtt+htttp+websocket
一.介绍 1.参考网址1:WebSocket协议:5分钟从入门到精通 2.参考网址2:WebSocket 教程(阮一峰) 二.应用 1.参考网址1:从 HTTP 到 MQTT:一个移动后端案例概述 2 ...
- Django框架(十):视图(三) Cookie、Session
1. Cookie Cookie,有时也用其复数形式Cookies,指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密).Cookie最早是网景公司的前雇员L ...
- PAT Advanced 1024 Palindromic Number (25) [数学问题-⼤整数相加]
题目 A number that will be the same when it is written forwards or backwards is known as a Palindromic ...
- Vue专题-组件
vue.js既然是框架,那就不能只是简单的完成数据模板引擎的任务,它还提供了页面布局的功能.本文详细介绍使用vue.js进行页面布局的强大工具,vue.js组件系统. Vue.js组件系统 每一个新技 ...