-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution2.java
46 lines (38 loc) · 1.09 KB
/
Solution2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
import java.util.*;
public class Solution2 {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[] s = new String[n];
int count = 0;
HashMap<Character,Integer> h = new HashMap<Character, Integer>();
for(int i=0;i<n;i++)
{
s[i] = sc.next();
char[] c = s[i].toCharArray();
TreeSet<Character> set = new TreeSet<Character>();
for(char ch : c)
{
set.add(ch);
}
for(char ch:set){
if(!h.containsKey(ch))
{
h.put(ch, 1);
}else
h.put(ch, h.get(ch)+1);
}
}
for(Character chr : h.keySet())
{
if(h.get(chr)==n)
{
count++;
}
}
System.out.println(count+"");
sc.close();
}
}