转自出处

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

For eg.. for the following input strings.. 



aghkafgklt 

dfghako 

qwemnaarkf 



The output should be 3. because the characters a, f and k are present in all 3 strings.

Note: The input strings contains only lower case alphabets

<pre name="code" class="java">public int getNumOfCommonChars(String[] inputs) {
// Return 0 if null / empty input or only one string is provided
if(inputs == null || inputs.length < 2) {
return 0;
} else {
//create an int array to hold # times character appears
int[] charCounts = new int[256];
for(String input : inputs) {
Set<Character> uniqueCharSet = new HashSet<Character>();
for(int i=0; i < input.length(); i++) {
char ch = input.charAt(i);
if (!uniqueCharSet.contains(ch)) {
uniqueCharSet.add(ch);
charCounts[(int) ch] += 1;
}
}
} int commonCharCount = 0;
for (int i=0; i < 256; i++) {
if (charCounts[i] == inputs.length()) {
commonCharCount++;
}
} return commonCharCount;
}
}


Write a program that gives count of common characters presented in an array of strings..(or array of的更多相关文章

  1. Find Common Characters - LeetCode

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

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

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

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

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

  4. [Swift]LeetCode1002. 查找常用字符 | Find Common Characters

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

  5. Find Common Characters LT1002

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

  6. 1002. Find Common Characters

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

  7. 【leetcode】1002. Find Common Characters

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

  8. LeetCode.1002-寻找共有字符(Find Common Characters)

    这是悦乐书的第375次更新,第402篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第236题(顺位题号是1002).给定仅由小写字母组成的字符串A,返回列表中所有字符串都 ...

  9. leetcode@ [315/215] Count of Smaller Numbers After Self / Kth Largest Element in an Array (BST)

    https://leetcode.com/problems/count-of-smaller-numbers-after-self/ You are given an integer array nu ...

随机推荐

  1. ERStudio8.0 破解版 下载

    下面地址亲测有效 https://blog.csdn.net/weixin_37139761/article/details/83856069

  2. PHP生成文档,并把数据加入文档的小案例

    PHP生成文档,可以利用file_put_contents($filename, $data),其中$filename表示文档名,$data表示需要放入的数据, 若存放的是数组,这还需要使用seria ...

  3. wampserver更改语言步骤

    wampserver更改语言步骤的具体步骤: 右击屏幕右下角图标>选择language>选择更改的语言

  4. C++暂停黑窗口

    C++中采用system("pause");来暂停黑窗口,那么操纵系统就会将窗口暂停,显示“请按任意键继续. . .” 我们用VS执行代码是,若直接按键盘的F5(开始调试),那么窗 ...

  5. GNU编译器学习 --> 如何链接外部库【Linking with external libraries】

    库也就是我们常说的library,一个库是若干个已经编译过的目标文件(.obj)的集合,它可以被链接到程序里.那么我们最常见的使用就是,我们在编程时会调用一些函数,这些函数别人已经写好了,它就放在库里 ...

  6. Mac使用Aria2下载百度网盘,突破下载限速的方法教程

    百度网盘目前可以说是在国内网盘环境中一枝独秀,日常使用触及在所难免,尤其是对于喜欢下载资源的朋友来说,但是一些限制让它的使用越来越难,尤其是下载速度,普通用户的下载往往远低于自己的预期,特别是对于 M ...

  7. 82-Ichimoku Kinko Hyo 一目平衡表.(2015.7.3)

    Ichimoku Kinko Hyo 一目平衡表 计算: 一目平衡图由五组参数合成,与现在常用的移动平均线吻合.参数基于各个长短周期的高低点,提供一明确简单的走势图.五个参数如下: 1.短轴快线 短轴 ...

  8. 转载:Django之Form组件

    Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 小试牛刀 1.创建Form类 +? 1 2 3 ...

  9. 集训第五周动态规划 J题 括号匹配

    Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...

  10. echarts的简单应用之(二)饼图

    接上一篇文章: echarts的简单应用之(一)柱形图:https://www.cnblogs.com/jylee/p/9359363.html 本篇文章讲述饼图,撇过折线图不说,是因为折线图与柱形图 ...