Algorithm--Find Common Characters
Find Common Characters
Title detail
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
1
2 Input: ["bella","label","roller"]
Output: ["e","l","l"]
Example 2
1
2 Input: ["cool","lock","cook"]
Output: ["c","o"]
Note:
1
2
3 1 <= A.length <= 100
1 <= A[i].length <= 100
A[i][j] is a lowercase letter思路
统计每个字符串中26个字母的出现次数。每个字符串都出现的字母且统计次数最少的即为结果输出的字符。
用int
数组0-25位置表示0-26个字母,存储的整数代表出现总次数。
Algorithm
1 | class Solution { |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 孙云增的博客!
评论