Leetcode-1002 Find Common Characters(查找常用字符)

 1 #define pb push_back
 2 #define maxSize 3939
 3 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
 4
 5 const int N = 101;
 6 class Solution
 7 {
 8     public:
 9         vector<string> commonChars(vector<string>& A)
10         {
11             int hash[N][N];
12             memset(hash,0,sizeof(hash));
13
14             int sz = A.size();
15             _for(i,0,sz)
16             {
17                 _for(j,0,A[i].size())
18                 {
19                     hash[i][A[i][j]-‘a‘] ++;
20                 }
21             }
22
23             vector<string> rnt;
24             for(int i = 0;i < 26;i ++)
25             {
26                 int mm = INT_MAX;
27                 for(int j = 0;j < sz;j ++)
28                 {
29                     mm = min(mm,hash[j][i]);
30                 }
31                 char aaa = ‘a‘+i;
32                 string aa;
33                 aa += aaa;
34                 for(int j = 0;j < mm;j ++)
35                 {
36                     rnt.push_back(aa);
37                 }
38             }
39             return rnt;
40         }
41 };

水题,没啥好说的

原文地址:https://www.cnblogs.com/Asurudo/p/10464596.html

时间: 2024-10-13 22:23:18

Leetcode-1002 Find Common Characters(查找常用字符)的相关文章

【Golang语言】LeetCode 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 i

Leetcode 1002. Find Common Characters

python可重集合操作 class Solution(object): def commonChars(self, A): """ :type A: List[str] :rtype: List[str] """ if not A: return [] from collections import Counter ans=Counter(A[0]) for str in A: ans&=Counter(str) ans=list(an

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

目录 题目描述: 示例 1: 示例 2: 解法: 题目描述: 给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表.例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次. 你可以按任意顺序返回答案. 示例 1: 输入:["bella","label","roller"] 输出:["e","l","l&

1002. 查找常用字符

给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表.例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次. 你可以按任意顺序返回答案. 示例 1: 输入:["bella","label","roller"] 输出:["e","l","l"] 示例 2: 输入:["cool&quo

1002. Find Common Characters - Easy

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

[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

Oracle中chr()和ascii()函数(附:常用字符与ascii对照表)

Oracle中chr()和ascii()函数(附:常用字符与ascii对照表) 关键字:chr() chr()函数作用:"特殊"字符特殊处理 在PLSql中可查询相对应的字码与特殊符 chr()函数示例: select chr(38) from dual;  ascii()函数示例: select ascii('&') from dual;      比如"&"到底为什么在Oracle中成了特殊字符呢?经过查找,终于揭晓了答案:原来&这个字符

[LeetCode] 158. Read N Characters Given Read4 II - Call multiple times

The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the file. By using the read4 API, implement the function

*字符串-01. 在字符串中查找指定字符

1 /* 2 * Main.c 3 * D1-字符串-01. 在字符串中查找指定字符 4 * Created on: 2014年8月18日 5 * Author: Boomkeeper 6 *****部分通过****** 7 */ 8 9 #include <stdio.h> 10 11 int mysearch(char ch, const char str[], int length) { 12 13 int j, ret = -1; 14 15 for (j = 0; j < le