转自出处

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. 循环实现数组 map 方法

    //循环实现数组 map 方法 const selfMap = function (fn, context) { let arr = Array.prototype.slice.call(this) ...

  2. caffe和图像一些基础知识

    1.卷积层的参数放置在convoluytion_param{}中,pad默认是0,stride默认是1,如果在convoluytion_param中没有写pad = 什么,或者stride = 什么, ...

  3. incremental linking(增量链接)的作用

    转:incremental linking(增量链接)的作用 今天编译一个C++程序时,报了一个奇怪的错误(之前是好好的): 1>LINK : fatal error LNK1123: fail ...

  4. SQL Server错误: 0 解决方案

    1.已设置两种登录模式. 2.SQL Server配置管理器已配置好. 按Windows徽标键+R组合键,然后输入cmd. 再然后输入netsh winsock reset.接下来重启电脑,应该就可以 ...

  5. vue按需加载组件-webpack require.ensure

    使用 vue-cli构建的项目,在 默认情况下 ,执行 npm run build 会将所有的js代码打包为一个整体, 打包位置是 dist/static/js/app.[contenthash].j ...

  6. js获取当前位置

    <!DOCTYPE html><html><head><meta name="viewport" content="initia ...

  7. Spring接收web请求参数的几种方式

    1 查询参数 请求格式:url?参数1=值1&参数2=值2...同时适用于GET和POST方式spring处理查询参数的方法又有几种写法: 方法一:方法参数名即为请求参数名 // 查询参数1 ...

  8. docker push

    一.确保docker hub上有账号 二.确认要提交的镜像的命名空间为自己账号名称 三.在本地登录docker: docker login 四.提交镜像: docker push zhengchuzh ...

  9. linux core dump 生成和调试

    core dump 某些信号的产生会导致产生core dump,包含了进程终止时的内存镜像.在某些时候这个core文件就非常的有用处,配合gdb或者lldb调试起来非常方便. 更详细的文档参考 Lin ...

  10. (转载)C++ string中find() ,rfind() 等函数 用法总结及示例

    string中 find()的应用  (rfind() 类似,只是从反向查找) 原型如下: (1)size_t find (const string& str, size_t pos = 0) ...